Server-side Redirects
When using server-side redirects you provide the URL of the API endpoint that will receive the token and other login session details as parameters. The native app will redirect the webview to this URL after a successful login. If the user has cancelled the login process, the error parameter will contain an error message.
GoNative JavaScript Bridge Methods and Parameters:
gonative.socialLogin.facebook.login({ 'redirectUri' : '<endpoint>', 'scope' : '<text>' });
gonative.socialLogin.google.login({ 'redirectUri' : '<endpoint>' });
gonative.socialLogin.apple.login({ 'redirectUri' : '<endpoint>', 'scope' : '<text>' });
redirectUri
- the GET endpoint that will be called after using the Social Login. The tokens will be added as GET parameters.
scope
- determines what data your app would like access to. Check the official documentation for each of the social logins for more information.
Redirect URL API Endpoint parameters:
Identity Provider | Status | Parameters | Example |
---|---|---|---|
Facebook Login | Success | accessToken=STRING type=facebook | https://yoursite.com/auth/facebook/redirect?accessToken=example&type=facebook&userId=1234567890 |
Facebook Login | Error | error=STRING type=facebook | https://yoursite.com/auth/facebook/redirect?error=error&type=facebook |
Google Sign-in | Success | idToken=STRING type=google | https://yoursite.com/auth/google/redirct?idToken=example&type=google |
Google Sign-in | Error | error=STRING type=google | https://yoursite.com/auth/google/redirect?error=error&type=google |
Sign in with Apple | Success | idToken=STRING code=STRING firstName=STRING 1 lastName=STRING 1 type=apple | https://yoursite.com/auth/apple/redirect?idToken=example&code=example&firstName=John&lastName=Doe&type=apple |
Sign in with Apple | Error | error=STRING type=apple | https://yoursite.com/auth/apple/redirect?error=error&type=apple |
1
Apple only returns the user's information the first time the user authorizes the app. Persist this information from your app; subsequent authorization requests will only contain an identity token in the form of JSON Web Token (JWT), authorization code, and user identifier to your app. Parsing this JWT will return many fields such as email
, email_verified
, etc. Refer to this documentation for more info.
Example:
<button class="google-login native-only"
onclick="gonative.socialLogin.google.login({ 'redirectUri' : 'https://demos.gonative.io/social-login/redirect-demo/redirect.html' });">
Log in With Google
</button>
In this example, the GoNative JavaScript Bridge endpoint is activated when the anchor tag is clicked. After the user has logged in within the native app, the webview will be redirected to https://demos.gonative.io/social-login/redirect-demo/redirect.html?idToken=example
.
Updated 5 months ago