ASP.NET MVC 5 Google Api mybusinessInformation

  Kiến thức lập trình

I try to get the reviews for an enterprise to show it on their website.

But I can’t connect, I have all ready uri redirect mismatch.

I am developing with ASP.NET MVC 5, C#, I tried app.authgoogleAuth for OAuth2, but it doesn’t work.

In startup.auth.cs, I have:

app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
      ClientId = "xxxMyClientID",
      ClientSecret = "xxxMyclientsecret"
});

In my controller:

private readonly IDataStore dataStore = new FileDataStore(GoogleWebAuthorizationBroker.Folder);

private async Task<UserCredential> GetCredentialForApiAsync()
{
    var initializer = new GoogleAuthorizationCodeFlow.Initializer
    {
        ClientSecrets = new ClientSecrets
        {
                 ClientId = "xxxMyClientId",
                 ClientSecret = "xxxMyClientSecret",
        },
        Scopes = MyRequestedScopes.Scopes,
    };

    var flow = new GoogleAuthorizationCodeFlow(initializer);

    var identity = await HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(
        DefaultAuthenticationTypes.ApplicationCookie); 
            
   var userId = identity.FindFirstValue(MyClaimTypes.GoogleUserId);

   var token = await dataStore.GetAsync<TokenResponse>(userId);
   return new UserCredential(flow, userId, token);
}

But identity is always null.

Can anyone help me?

Thanks

New contributor

M.S.WebFustion is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT