Social Login (OAuth)
To initiate sign in, you can use the initOAuth()
method from the Openfort JavaScript library and provide a redirectTo
URL which points to a callback route.
- Implicit flow: that's all you need to do. The user will be taken to Google's consent screen, and finally redirected to your app with an access and refresh token pair representing their session.
- Pooling flow: for example in Server-Side Auth, you need to redirect the user back to your website.
You will need to call the initOAuth
method:
_10import {OAuthProvider} from "@openfort/openfort-js";_10_10await openfort.initOAuth({_10 provider: OAuthProvider.GOOGLE, // or FACEBOOK, TWITTER, etc._10 options: {_10 // Depdening on the flow_10 // redirectTo: 'https://your-website.com/login',_10 // usePooling: true,_10 },_10});
Configure your social login providers at your dashboard. Follow the guide on how to configure social login to learn more.
Configure your social login providers from your dashboard. Follow the guide on how to configure social login to learn more.
The supported loginMethods are 'google'
, 'twitter'
, 'discord'
, 'facebook'
or 'epic_games'
.
Now you can redirect the user to the initOAuth.url and when the process is done, you will be redirected to the redirectTo url with tokens https://your-website.com?access_token=...&refresh_token=...&player_id=...
You can then use those parameters to authenticate the user:
_10openfort.storeCredentials({_10 player: player_id,_10 accessToken: access_token,_10 refreshToken: refresh_token,_10 });
Uppon successful authentication, the SDK will return a token that can be used to authenticate the user in your application.