Skip to content

Get Access Token "Malformed" Error #64

Closed
@timnlupo

Description

@timnlupo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions