UniWebViewAuthenticationFlowGoogle
Summary
A predefined authentication flow for Google Identity.
This implementation follows the flow described here.
Google authentication flow is a bit different from the other standard authentication flows. Please read the link above carefully to understand it.
See the OAuth 2.0 Support for a more detailed guide of authentication in UniWebView.
To allow the Google flow working, at least you need these steps:
- Setting
Client Id
,Redirect Uri
in theUniWebViewAuthenticationFlowGoogle
inspector. - Setting
Scope
and at least containshttps://www.googleapis.com/auth/userinfo.profile
in theUniWebViewAuthenticationFlowGoogle
inspector. - Setting the
Auth Callbacks Urls
containingcom.googleusercontent.apps.${first_part_of_client_id}:${redirect_uri_path}
in theUniWebView
preference panel.
Make sure to get the correct client Id and callback URL values from the Google API Console Credentials page.
Properties Summary
The client ID of your Google application. | |
The redirect URI of your Google application. | |
The scope of your Google application. | |
Optional to control this flow's behaviour. | |
Whether to enable PKCE when performing authentication. | |
Whether to enable the state verification. | |
If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server. |
Events Summary
Called when the authentication flow succeeds and a valid token is generated. | |
Called when any error (including user cancellation) happens during the authentication flow. | |
Called when the access token refresh request finishes and a valid refreshed token is generated. | |
Called when any error (including user cancellation) happens during the authentication flow. |
Methods Summary
Starts the authentication flow with the standard OAuth 2. | |
Starts the refresh flow with the standard OAuth 2. |
Properties
The client ID of your Google application.
Example
At the day of writing, the client Id from Google is something like:
googleFlow.clientId = "1234567890-abcdefgh.apps.googleusercontent.com";
The redirect URI of your Google application.
It might be something like "com.googleusercontent.apps.${clientId}:/${redirect_uri_path}". Be caution that the URI does not contain regular double slashes //
, but should be only one.
Example
googleFlow.redirectUri = "com.googleusercontent.apps.1234567890-abcdefgh:/auth";
The scope of your Google application.
It might be some full URL in recent Google services, such as "https://www.googleapis.com/auth/userinfo.profile"
Optional to control this flow's behaviour.
Whether to enable PKCE when performing authentication. Default is S256
.
Whether to enable the state verification. If enabled, the state will be generated and verified in the authentication callback.
Default is true
.
If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Google Authentication Server.
Events
Called when the authentication flow succeeds and a valid token is generated.
Example
googleFlow.OnAuthenticationFinished.AddListener(OnGoogleTokenReceived)
void OnGoogleTokenReceived(UniWebViewAuthenticationGoogleToken token) {
Debug.Log("Google Access Token: " + token.AccessToken);
}
Called when any error (including user cancellation) happens during the authentication flow.
Example
googleFlow.OnAuthenticationErrored.AddListener(OnGoogleAuthError);
void OnGoogleAuthError(long error, string message) {
Debug.Log("Error code: " + error + " Message: " + message);
}
Called when the access token refresh request finishes and a valid refreshed token is generated.
Example
googleFlow.OnRefreshTokenFinished.AddListener(OnRefreshTokenReceived)
void OnRefreshTokenReceived(UniWebViewAuthenticationGoogleToken token) {
Debug.Log("Access Token: " + token.AccessToken);
}
Called when any error (including user cancellation) happens during the authentication flow.
Example
googleFlow.OnRefreshTokenErrored.AddListener(OnRefreshTokenError);
void OnRefreshTokenError(long error, string message) {
Debug.Log("Error code: " + error + " Message: " + message);
}
Methods
Starts the authentication flow with the standard OAuth 2.0. This implements the abstract method in UniWebViewAuthenticationCommonFlow
.
Starts the refresh flow with the standard OAuth 2.0. This implements the abstract method in UniWebViewAuthenticationCommonFlow
.