Skip to content

Get Access Token "Malformed" Error #64

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

Closed
timnlupo opened this issue Sep 27, 2018 · 2 comments
Closed

Get Access Token "Malformed" Error #64

timnlupo opened this issue Sep 27, 2018 · 2 comments

Comments

@timnlupo
Copy link

Hi everyone,

I am trying to authenticate my app to make REST calls to Google from Unity. I successfully generate an authCode from logging in with this API with the following configuration.

configuration = new GoogleSignInConfiguration {
	WebClientId = webClientId,
	UseGameSignIn = false,
	RequestIdToken = true,
	RequestAuthCode = true,
	AdditionalScopes = scopes
};

I'm now trying to exchange my authCode for an accessToken so I can make REST calls to different APIs. I referenced #57 and my code for this is below.

WWWForm formData = new WWWForm();
formData.AddField("client_id", webClientId);
formData.AddField("client_secret", webClientSecret);
formData.AddField("grant_type", "authorization_code");
formData.AddField("code", "AuthCode");

UnityWebRequest www = UnityWebRequest.Post("https://www.googleapis.com/oauth2/v4/token", formData);

I get a 400 Generic/unknown HTTP error with the response { "error": "invalid_grant", "error_description": "Malformed auth code." }. What is going wrong? Am I able to use a webClientID to access Google API from REST? Is there a problem with authCode generation? Please advise, thanks.

@timnlupo
Copy link
Author

I hate myself. I've been debugging for like 5 hours. In the line formData.AddField("code", "AuthCode"); I put " around AuthCode. I wasn't sending my actual variable lol, it's all fixed now.

@vlon
Copy link

vlon commented Nov 27, 2019

Hi, How is authcode generated, I am stuck here

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