Ionic 2 add the local address to the remote address to contact - http

My queries with Ionic 2 (2.0.0-beta.10) to a site outside back with a 404 :
var url = 'https//api.mysite.fr/example;
return this.http.get(url).map(res => res.json());
Response in chrome tool :
Failed to load resource: the server responded with a status of 404 (Not Found)
url: "http://localhost:8100/https//api.mysite.fr/example"
How to not add the local execution url to the remote address to contact?

You're missing the : after the url scheme. It should be: var url = 'https://api.mysite.fr/example;

Related

Active directory login not working with error "The reply URL specified in the request does not match the reply URLs configured for the application"

I have configure the active directory login as per document but its always give me error "The reply URL specified in the request does not match the reply URLs configured for the application"
My configuration and setting as below.
appsettings.json
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "https://localhost:44300/",
"ClientId": "94652b2b-ac2d-470c-b8a8-8ce7c7691aca",
"TenantId": "0ef71077-dc27-4e28-a028-a10542145dfc",
"CallbackPath": "/signin-oidc"
}
Startup.cs
ConfigureServices method
services.AddRazorPages()
.AddMicrosoftIdentityUI();
services.Configure<CookiePolicyOptions>(option =>
{
option.CheckConsentNeeded = context => true;
option.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(AzureADDefaults.AuthenticationScheme).AddAzureAD(option => Configuration.Bind("AzureAd", option));
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, option =>
{
option.Authority = option.Authority + "/V2.0/";
option.TokenValidationParameters.ValidateActor = false;
});
services.AddMvc(option =>
{
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
option.Filters.Add(new AuthorizeFilter(policy));
})
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
Its always ask me for login but after login i got below error message
Sorry, but we’re having trouble with signing you in.
AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application: '94652b2b-ac2d-470c-b8a8-8ce7c7691aca
Below is my active directory login configuration
Redirect URIs : https://localhost:44300/
Access tokens = checked
ID tokens = checked
Supported account type: Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
I have answered similar questions before, please see:here.
There is a general solution to the problem of not match:
When you visit the application url , you will be redirected to the login page. Decode the authorization request URL, you will find redirect_uri, copy the value of redirect_uri and paste it into the azure portal, and try again.
For the redirect URL, it should start with https, if you need to start with http, you must configure it as http://localhost.

Problem using http GET request in flutter

So I got a template of a Flutter app that retrieves all its data from a website using HTTP get requests.
I have the following method that gets the list of resturaunts:
Future<Stream<Restaurant>> getNearRestaurants(LocationData myLocation, LocationData areaLocation) async {
String _nearParams = '';
String _orderLimitParam = '';
if (myLocation != null && areaLocation != null) {
_orderLimitParam = 'orderBy=area&limit=5';
_nearParams = '&myLon=${myLocation.longitude}&myLat=${myLocation.latitude}&areaLon=${areaLocation.longitude}&areaLat=${areaLocation.latitude}';
}
final String url = '${GlobalConfiguration().getString('api_base_url')}restaurants?$_nearParams&$_orderLimitParam';
final client = new http.Client();
final streamedRest = await client.send(http.Request('get', Uri.parse(url)));
return streamedRest.stream.transform(utf8.decoder).transform(json.decoder).map((data) => Helper.getData(data)).expand((data) => (data as List)).map((data) {
return Restaurant.fromJSON(data);
});
}
However when I swap the template's url variable for my own website, the app gets stuck since it cannot retrieve the same information from my website.
What could I be missing? Is the problem in the flutter code or the website?
Update 1:
I surrounded it with a try/catch block and it gave me a "bad certificate exception.". This might be because my website does not have a SSL certificate, so I added an exception to the HttpClient for my self-certified website:
bool _certificateCheck(X509Certificate cert, String host, int port) =>
host == '<domain>';
HttpClient client2 = new HttpClient()..badCertificateCallback = (_certificateCheck);
HttpClientRequest request = await client2.getUrl(Uri.parse(url));
var response = await request.close(); // sends the request
// transforms and prints the response
response.transform(Utf8Decoder()).listen(print);
This code showed a Error 404: Not found on the page that I need to get my JSON data from.
I also installed postman and checked my website with the GET statement for the same list of restaurants I try to retrieve in the flutter code posted above and see this:
Postman GET screenshot
Update 2:
So I configured SSL on my website and the problem still persists. I tried testing the GET request via postman and it returns a error 404 page as well. I have tried going through my server files and laravel logs and nothing did the trick.
Its as if my website cannot route to the specific pages in my API folder. BUt they are all defined in api.php.

Unknown http error with http request to an iis server with ionic

I've got a problem with my ionic app. I try to get a json object from my iis (asp.NET) server. But the request doesn't even come into my controller. Everytime, i get the same error:
http failure response for (unknown url) 0 unknown error
At first, I thought it was just a cors problem so i fixed it but now, it works with chrome and internet explorer 11 but not with edge and, more important, it doesn't work on device.
I don't think the problem is with my typescript code since there is no problem with a Google request... But, just in case, there is my code:
this.http.get('http://localhost:60196', {withCredentials : true}).subscribe(data => {
this.testData = JSON.stringify(data);
}, err => {
this.testData = JSON.stringify(err);
});
For the record: my iis server use windows impersonation and my app must run on windows devices (i didn't try my code with android or ios devices).
Thank you very much.
it doesn't work on device
this.http.get('http://localhost:60196', {withCredentials : true}).subscribe(data => {
this.testData = JSON.stringify(data);
}, err => {
this.testData = JSON.stringify(err);
});
Get request is rerencing to localhost. Here should be some Api endpoint when testing it on device...

Changing .Net Core OpenID Connect Authorization Flow 'redirect_uri' value

I've configured a .Net Core Web app to use OpenID Connect for authentication using the Authorization Code model as per my IdP sample instructions (https://www.onelogin.com/blog/how-to-use-openid-connect-authentication-with-dotnet-core):
services.AddAuthentication(options => {
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(o => {
o.ClientId = "[Client ID]";
o.ClientSecret = "[Client Secret]";
o.Authority = "[Authority]";
o.ResponseType = "code";
o.GetClaimsFromUserInfoEndpoint = true;
});
Then my controller is set up to require authentication:
[Authorize]
public IActionResult About()
{
ViewData["Message"] = "You must be authenticated to view the About page";
return View();
}
I also have configured ngrok to provide a temporary public URL which should be used in the authentication flow redirect back to my site using:
ngrok http 5000 -host-header="localhost:5000"
This command successfully sets up the proxy and once running, I can browse to the site via the proxy url (e.g. https://75c97570.ngrok.io).
The issue I'm running into is that when I attempt to browse to the 'About' page I'm redirected to the IdP site and prompted to log-in as expected, however, the 'redirect_uri' value passed via the query string is my 'localhost' address (https://localhost:5000/signin-oidc) not the ngrok proxy address (https://75c97570.ngrok.io/signin-oidc). This is causing an issue because my IdP requires a non-local url (hence the ngrok proxy), so the redirect_uri value being passed (localhost) doesn't match the one configured in my IdP account (ngrok) and I receive an error message that the 'redirect_uri did not match any client's registered redirect_uris'.
I'm assuming this is a .Net configuration issue. Is there a way to tell .Net to use the ngrok proxy address for the 'redirect_uri' value on redirect as opposed to the localhost address? I've tried using the 'CallbackPath' option on the OpenID Connect configuration options, however it appears that this only allows for a sub-path of the current url (e.g. http://localhost:5000/[something]) and can't be used to specify a completely different url. Is there another way to configure the redirection to use the proxy url?
Thanks!
Ok, after some digging I found one solution to this issue. I added the following code to the initialization of my OpenIdConnect service:
.AddOpenIdConnect(o => {
...(snip)...
o.Events.OnRedirectToIdentityProvider = (context) =>
{
context.ProtocolMessage.RedirectUri = "https://75c97570.ngrok.io/signin-oidc";
return Task.FromResult(0);
};
...(snip)...
}
This does the trick of changing the 'redirect_uri' value which is passed to my IdP on the redirect. Not sure if this is the best way to handle this, however it does work.

Signalr negotiate url fails

Trying to get signalr up and running.
I keep getting 2 errors back from the server:
GET negotitate url returns 500 Internal Server Error
XMLHttpRequest cannot load http://localhost:10772//signalr/negotiate ...
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500.
Screenshot provided.
Any ideas?
]1
OK, found it out myself. Spelling error.
The name of the hub mentioned was incorrect.
changed:
var proxy = this.connection.createHubProxy('chattAppHub');
to:
var proxy = this.connection.createHubProxy('ChatAppHub');
In the backend:
[HubName("ChatAppHub")]
public class ChatAppHub : Hub ...
inside startup.cs
var hubConfiguration = new HubConfiguration();
hubConfiguration.EnableDetailedErrors = true;
appBuilder.MapSignalR(hubConfiguration);
appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
This fixed it for me:
C# Startup.cs tweak:
app.MapSignalR(new HubConfiguration{EnableJSONP = true});
JavaScript tweak:
connection.start({ jsonp: true })
We need JSONP anyways so for us it was a good solution.
I had the same problem, it is all about CORS.
You should add Host URL in CORS config in Sturtup.cs, Have look at:
https://stackoverflow.com/a/59891997/854405

Resources