How to integrate Google SingIn react native and Spring Boot Security OAuth2?

1k views Asked by At

I have a mobile app in react native that uses expo-auth-session to be able to log in with its google account.

I have spring boot application that has oauth2 configuration as you can see below:

spring:
  security:
    oauth2:
      client:
        registration:
          google:
            clientId: clientIdValue
            clientSecret: clientSecretValue
            redirectUri: "https://localhost/oauth2/callback/{registrationId}"
            scope:
              - email
              - profile

How can i integrate this react-native app to works with spring boot application in signin/signup?

I need to be able to authenticate the user on my backend to get a jwt token so I can access the rest of my endpoints.

The problem I find is that if I use the oauth2 library of my spring boot using these urls: https://localhost/oauth2/authorize/google? redirect_uri=https://localhost/oauth2/redirect. i can't redirect to my mobile app and if I use expo-auth-session to login the user from my mobile app, i don't have the necessary information to authenticate with oauth2 in my backend.

What is the best way to do this? Is there a way to redirect back to my mobile app after authentication in my backend? I know that I can know if the call was from mobile using userAgentInfo

1

There are 1 answers

0
ch4mp On

Your Spring app is most probably a REST API, and as so, a resource-server, not a client, which means your Spring conf is most probably wrong. Tutorials for configuring resource-servers on this repo of mine

Regarding your React-Native app, you could consider make it an OAuth2 client with the help of react-native-app-auth. I have no direct experience with React Native, but with Cordova apps, it required me to setup "deep links" for redirection back from authorization server.