How to fix Google ASM authentication issue when using Google OAuth in .NET MVC application on Google Cloud?

27 Views Asked by At

Flow :- Once Web Application Run, It ask for credential i.e. google credentail e.g. [email protected] which redirect to Azure AD login, so fill the same [email protected] and PWD, Below is a code for Authentication.

The issue is Google ASM http://localhost:XXXXX/_gcp_asm_authenticate not working Please do not ask why Google ASM in between.

If I replace with options.CallbackPath = "/auth"; and IN Authorized redirect URIs http://localhost:XXXXX/auth working.

  • MVC .NET Application

  • Deployed on Google Cloud

  • Google OAuth consent screen Done

  • Build OAuth 2.0 Client IDs Done

  • Authorized redirect URIs http://localhost:XXXXX/_gcp_asm_authenticate

Program.cs

 return options =>
    {
        options.Authority = "https://accounts.google.com";
        options.ClientId = "34-43434343434.apps.googleusercontent.com"; 
        options.ClientSecret = "ooooo-xxxxxxxx";
       
        options.SaveTokens = true;
        options.Scope.Add("https://www.googleapis.com/auth/userinfo.profile");
        options.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
        options.ResponseType = "code";

        
        options.CallbackPath = "/_gcp_asm_authenticate";
        options.Events = new OpenIdConnectEvents()
        {
            OnTokenValidated = async context =>
            {
                if (context.Principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value.Contains("alok"))
                //if (context.Principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value == "23232323")
                {
                    var claim = new Claim(ClaimTypes.Role, "Teacher");
                    var claimsIdentity = context.Principal.Identity as ClaimsIdentity;
                    claimsIdentity.AddClaim(claim);
                }
            }
        };
    };

Expecting User Login -> Google Login -> Azure AD Login work with Google Oauth + Google ASM. [uthorized redirect URIs** **http://localhost:XXXXX/_gcp_asm_authenticate]

0

There are 0 best solutions below