Christian Niochet
Christian Niochet

Reputation: 13

How can I give access from my swagger api to OAuth?

I have been using the google OAuth library in C# to use it in my API service. Making the request to be able to get the access token through this code:

`string clientId = "my client id"; string secretId = "my secret";

        string[] scope = { "https://www.googleapis.com/auth/business.manage" };

        var credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = clientId,
                ClientSecret = secretId
            }, scope, "user", CancellationToken.None).Result;

        if (credentials.Token.IsExpired(SystemClock.Default))
            credentials.RefreshTokenAsync(CancellationToken.None).Wait();`

It redirects me to the usual google window to get access via your google account login tells me:

Error 400: redirect_uri_mismatch

Which is strange because with my tests in OAuth 2.0 Playground, it worked perfectly. The purpose of this is to get the access code to be able to use it for the authorize of that business link (in case you want to point it out).

It should be noted that in the configuration of my Credentials api of my google console I added the url of my localhost (I added both the https://localhost and also the https://localhost:5244 of my service).

Upvotes: 1

Views: 143

Answers (1)

John
John

Reputation: 16

Try to choose the different application type when are you creating oauth client id from the Google Console such as Web Application or desktop Application. bcoz i'm getting the same error which was resolved by change the Application type to "Web Application". Oauth client Id Application form

Upvotes: 0

Related Questions