Directus + Google SSO + React Native

Dear All,

I’m creating mobile app using react-native. For regular login (email/password) already works. But, I want to add Google Seamless SSO.

After, choosing a google account and accept the permission request, it successful. But it can’t access another endpoints like /users/me because it didn’t have correct directus token. How to exchange from google token to directus token? Please help. TIA.

Google userInfo structure: {
“type”: “success”,
“data”: {
“scopes”: [
“``https://www.googleapis.com/auth/userinfo.profile”``,
“``https://www.googleapis.com/auth/userinfo.email”``,
“openid”,
“profile”,
“email”
],
“serverAuthCode”: “4/0AVMBsJi7Oj–redacted–p_xG_Ba9NtJViLWkoyXLyyklz6qPqs7P30kLgJL7bHKw”,
“idToken”: “eyJhbGciOiJSUzI1NiIsImtpZCI6IjE0OTljMTU0Y2NjOGEyNWUyNGQ4ZGU4YjFhOWY4NDVhZWZiNmYzY2EiLCJ0eXAiOiJKV1QifQ.eyJpc–redacted–tdP2S6HutKqzTqEAlItFCt9HuqfXDLFmnT4nIa9x_DXuLbaeg3o8TTJc6QvQ”,
“user”: {
“photo”: “``https://lh3.googleusercontent.com/a/ACg8ocIqgXsDHDSxNFQ5G8–redacted–4g=s96-c”``,
“givenName”: “Yo”,
“familyName”: null,
“email”: “yo–redacted–@gmail.com”,
“name”: “Yo”,
“id”: “10906–redacted–638106”
}
}
}

Hello @ymys

On web, Directus can handle Google OAuth directly with redirects, but on mobile apps the flow is different. From what I’ve seen, you usually need two things:

  1. A custom endpoint in Directus that takes the Google token, verifies it, and exchanges it for a Directus access token.

  2. A deeplink in the React Native app to finish the sign-in flow and pass the token back to the app.

Hello @ymys

This might help Login with SSO - React native · directus/directus · Discussion #11080 · GitHub