Error 404 - connect to Gmail API from MVC Application - gmail-api

I have problem. I try to connect with Gmail API from my MVC application. On my local machine all works fine but when I deploy application to IIS I get 404 error. It is caused by redirect application to "http://localhost/AuthCallback/IndexAsync" address when the correct is "http://localhost/myApplicationName/AuthCallback/IndexAsync".
Can I change default redirect url?
I get error after user authorization.
I'm using Google.Apis Version 1.9.1.12395 and GoogleApis.Gmail.v1 version 1.9.0.31.

Ok, I resolve problem. I had to override parameter in class AppFlowMetadata
public override string AuthCallback
{
get
{
return #"/ApplicationName/AuthCallback/IndexAsync";
}
}

Related

Blazor authentication with Azure Active Directory and custom base URI

I have a blazor webassembly application that implements authentication using Azure Active Directory. Everything works fine.
Now I need to change the base URI of the application from / to /app. I did that following the steps here.
Doing the above broke the authentication flow. Now the application is stuck in this url https://localhost:7105/app/authentication/login?returnUrl=https%3A%2F%2Flocalhost%3A7105%2Fapp.
Looking in the console I found the following stack :
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Invalid return url. The return url needs to have the same origin as the current page.
System.InvalidOperationException: Invalid return url. The return url needs to have the same origin as the current page.
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore`1[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=6.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].GetReturnUrl(RemoteAuthenticationState state, String defaultReturnUrl)
at Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticatorViewCore`1.<OnParametersSetAsync>d__82[[Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationState, Microsoft.AspNetCore.Components.WebAssembly.Authentication, Version=6.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
It says the return url is invalid. I can't figure out where this return url is set and what to change it for.
Thanks to #TinyWang for pointing to the github issue. The workaround was to append a "/" at the end of the return url:
var uri = Navigation.Uri;
if (uri.EndsWith("/app")) uri += "/";
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString((uri))}");
To add my two cents, since in this case the return url is the landing page of the app, this works fine too:
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.BaseUri)}");

Can not remove AWS Amplify Auth

I have a web app using the following amplify resources:
Auth
API
Function
Hosting
I have been having issues with the Auth service giving the following network error when going through the Auth0 flows:
error message in the headers:
x-amzn-errormessage: IdentityPool 'us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found.
Error message in console:
POST https://cognito-identity.us-east-2.amazonaws.com/ 400
So I am trying to completely remove the Auth section and try and build it again from scratch.
However, when I run:
amplify remove auth
it removes the Auth in my local code, but then won't allow me to "amplify push" or "amplify publish" because the auth service can not be found 🤦🏼‍♂️🤦🏼‍♂️🤦🏼‍♂️ and I get this message:
Template error: instance of Fn::GetAtt references undefined resource auththisismyappg986421b An error occurred during the push operation: Template error: instance of Fn::GetAtt references undefined resource auththisismyappg986421b
Anyone know how to solve this? or advice on how to get
AWS Amplify - React - React Router (using protected routes) to all play along nicely?
Do you have any other resources that depend on auth? (api, storage, etc.)
If you do, when you do remove auth you get this warning:
You have configured resources that might depend on this Cognito resource. Updating this Cognito resource could have unintended side effects.
Judging from you message you might have an API that depends on your Auth. Look at amplify/api/YOURAPI/parameters.json, you should have
{
"AppSyncApiName": "YOURAPI",
"AuthCognitoUserPoolId": {
"Fn::GetAtt": [
"auththisismyappg986421b",
"Outputs.UserPoolId"
]
}
}
Therefore a dependency to your deleted auth still exists and Amplify does not like that.
What you can do is create your new auth from scratch, then you'll get a new userPoolID let's say auththisismyappgXXXXXXX and replace every instances of auththisismyappg986421b with auththisismyappgXXXXXXX.
Edit: by the way if anyone has a way to do it more cleanly through amplify CLI that would be nice :)

How to fix "net::ERR_CERT_AUTHORITY_INVALID" when sending a request to an https:// API?

I have a React application (create-react-app) running on http://localhost:3000/ and I need to send a request to an API (Java with Spring Boot) that is available on "https://review-feature-...api/partner".
However, when I send the request, I get the following error on my Chrome console:
POST https://review-feature-...api/partner net::ERR_CERT_AUTHORITY_INVALID
I've tried to change my React application to run on https://localhost:3000, but it doesn't work because I have a Keycloak authorization server running behind my React app, so I have to find a way to send the request using http://localhost:3000/ anyway.
I've also tried to use the following environment variables (How can I provide a SSL certificate with create-react-app?) but it doens't work.
SSL_CRT_FILE=.cert/server.crt
SSL_KEY_FILE=.cert/server.key
Thanks in advance.

Spring boot & Spring Security : Forward the invalid urls

I work with spring boot, thymeleaf, spring security and angularjs
I want all url invalid to return to the home page.
The login page is managed by thymeleaf and the rest by angularjs
So i used a #Controller to forward all invalid url to the localhost:8080/:
#Controller
public class AccueilController {
// Match everything without a suffix (so not a static resource)
#RequestMapping(value = "/{path:[^\\.]*}")
public String redirect() {
// Forward to home page so that route is preserved.
return "forward:/";
}
}
when connecting if I type localhost:8080/XXXXthat forward me to the racine after login but if I type localhost:8080/XXXX/XXXX that give me a 404 error
after connection I don't have that problem because Angular forward all url correctly.
That's not the default behavior of the web applications. I sugest you to customize the not found page (Spring Boot and custom 404 error page) and then from there create a link to your home;

Hosting nancy with asp.net on IIS 6 - failed - wrong configuration

I tried some stuff to host a little nancy test api under IIS 6:
https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-asp.net
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
But it dont work. Here are my steps:
Create Empty Nancy Web Application
Add Reference with nuget - Nancy.Hosting.Aspnet Version 0.15.1
new Web.config is modifyed automatically
as described in the wiki
Add new class in solution root - HelloModule.cs
insert test code "HelloWorld"
Publish the web site local
on Windows 2003
with a virtual Directory in the IIS manager
Browsing the url 'localhost/nancyTest' brings an HTTP 403 ERROR.
A little ASP.NET WebApplication runs with the same configuration.
The nancyTest application does not have a start site like default.aspx. I want to get the request response from .../nancyTest/ coded as:
public class HelloModule : NancyModule
{
public HelloModule()
{
Get["/"] = parameters => "Hello World";
}
}
Perhaps the call .../nancyTest/ is not a GET Request? Are there other things to go in more detail?
I know not so many people user IIS6 nowadays, but there is the following solution, i wish it can help some people that still use this old one,
Config aspnet_isapi to handle a new ext files and like , .start
Set default page for this application is index.start
In nancy module add the redirect method, like the follwing:
Get["index.start"] = _ => {
return Response.AsRedirect("~/", Nancy.Responses.RedirectResponse.RedirectType.Permanent);
};
wish it helps

Resources