Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'OAuth realm="https://accounts.google.com/OAuthGetRequestToken"'. #232

Open
Swapygit opened this issue Sep 15, 2020 · 3 comments

Comments

@Swapygit
Copy link

Hi Team,

I am trying to link to google adwords account using Oauth2 in C# .net . However, I am getting the following error,

MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'OAuth realm="https://accounts.google.com/OAuthGetRequestToken"'. [Returned while handling POST Request]

I had a communication regarding this with the Google Adwords support team. They had following reply for this

It looks like the issue is specific to the client library that you're using. Could you please post your concern on the Github issue tracker so the library owners can assist you on this

Kindly suggest what can I do to resolve the exception

Please find the below details regarding the issue which will help you to find the root cause.

We are not using WCF service.We are not using Google Ads Api. We are using Google Adwords API v201809.

Please find below the steps we are following.

We are using ASP.NET MVC Web API. We have a mobile app where user clicks on Connect to google adwords. When the user clicks the button he is redirected to google sign in page and after sign in it is re directed to the back end MVC web API along with the server token. We use this server token and fetch the customer using the service.getCustomers() method of the Google AdWordsService.v201809.CustomerService.

Please find the below code we have used

Customer c = new Customer();

       Selector selector = new Selector()
       {
           fields = new string[] { Convert.ToString(c.customerId), c.descriptiveName }
       };

       CustomerService service =
       (CustomerService)user.GetService(AdWordsService.v201809.CustomerService);

       Customer[] cst = service.getCustomers();

And according to our error logs we are getting the error on the line

Customer[] cst = service.getCustomers();

Also, this error does not occur for all the users. Suppose, out of 100 we are get this error 1 or 2 customer.
If the error was due to code, then it should have occurred for all the users. But that's not the case.
Looking forward for your response.

Thanks.
Swapnil

@Swapygit
Copy link
Author

Swapygit commented Sep 15, 2020

One more information

We are not using proxy servers for connecting google adwords api.

We are using web app flow.

Let me describe my current flow

User click connect adwords button in our app (App is build on ionic cardova.)
User is redirected to google login for authentication (We are using https://github.com/EddyVerbruggen/cordova-plugin-googleplus plugin to handle this )

library version of googleplus plugin is

cordova.system.library.4=com.google.android.gms:play-services-auth:+
cordova.system.library.5=com.google.android.gms:play-services-identity:+

After successful login this plugin return following response
obj.email // '[email protected]'

obj.userId // user id

obj.givenName // 'Eddy'

obj.imageUrl // 'http://link-to-my-profilepic.google.com'

obj.idToken // idToken that can be exchanged to verify user identity.

obj.serverAuthCode // Auth code that can be exchanged for an access token and refresh token for offline access

obj.accessToken // OAuth2 access token

Using obj.serverAuthCode we start account linking process.
To start account linking we are we are using serverAuthCode to generate access token and refresh token for offline access
For this we are using FetchAccessAndRefreshTokens(apireq.servertoken) method from google adwords api v201809 (.net library)

Now for all users its working properly , but for some we are getting error in

Google.Api.Ads.AdWords.v201809.CustomerService.getCustomers() method.

@Swapygit
Copy link
Author

Below is the stack trace and URL which caused this error.

Message: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'OAuth realm="https://accounts.google.com/OAuthGetRequestToken"'.

let me know if you need more information.

@mwilc0x
Copy link

mwilc0x commented Oct 29, 2020

Duplicate of #216

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants