Hi, I’m trying to implement Google Auth using realm-web but I’m getting error during exchanging authCode for accessToken with stitch service
app.logIn(Realm.Credentials.google(authCode));
stitch respond with
{error: "error exchanging access code with OAuth2 provider", error_code: "AuthError",…}
My Google OAuth2 Client
Client ID for Web application
Authorized JavaScript origins
URI: [https://realm.mongodb.com]
Authorized redirect URIs: [
https://realm.mongodb.com/api/client/v2.0/auth/callback,
https://realm.mongodb.com/api/client/v2.0/auth/callback,
https://us-west-2.aws.realm.mongodb.com/api/client/v2.0/auth/callback,
https://eu-west-1.aws.realm.mongodb.com/api/client/v2.0/auth/callback,
https://ap-southeast-2.aws.realm.mongodb.com/api/client/v2.0/auth/callback,
https://stitch.mongodb.com/api/client/v2.0/auth/callback]
my oauth2-google.json
{
"id": "5fc81536e620d067d2edcfac",
"name": "oauth2-google",
"type": "oauth2-google",
"config": {
"clientId": "10571797xxxx-xxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"
},
"secret_config": {
"clientSecret": "google_ouath_client_secret"
},
"disabled": false
}
client app
<GoogleLogin
clientId="10571797xxxx-xxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"
buttonText="Login"
responseType="code"
onSuccess={(response) => {
if (response.code) {
loginWithGoogle(response.code);
}
}}
onFailure={(response) => {/*omited*/}}
/>
const loginWithGoogle = async (authCode: string) => {
try {
await app.logIn(Realm.Credentials.google(authCode));
} catch (e) {
console.error(e)
}
};
Yes, I’m using responseType="code"
, and I successfully receive authCode from Google.
But, HTTP call of app.login
looks like this
Request URL: https://stitch.mongodb.com/api/client/v2.0/app/xxxxxxx-app-pozwq/auth/providers/oauth2-google/login
Request Method: POST
Status Code: 401
Remote Address: 52.16.113.157:443
Referrer Policy: strict-origin-when-cross-origin
{"authCode":"4/0AY0e-g6OJPnXe4KLQYWOYSkm2b6aWxxxxxxxxxxxxxxxxxxxxxxxx","options":{"device":{"sdkVersion":"1.0.0","platform":"chrome","platformVersion":"86.0.4240","deviceId":{"$oid":"5fc802b2723axxxxx"}}}}
Response
{"error":"error exchanging access code with OAuth2 provider","error_code":"AuthError","link":"https://realm.mongodb.com/groups/5f71b53f1bbd91xxxxxxxxxxxxxxxxxxxxxxxxx"}
What am I doing wrong ?