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 - General and OAuth 2.0 with Google for a more detailed guide of authentication in UniWebView.
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. | |
The prompt that will be set to the authentication request query. | |
The additional query arguments that are used to construct the query string of the authentication request. |
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.
The prompt that will be set to the authentication request query. For example, the possible values can be login
, consent
, select_account
and so on.
See https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
The additional query arguments that are used to construct the query string of the authentication request.
This is useful when you want to add some custom parameters to the authentication request. This string will be appended to the query string that constructed from GetAuthenticationUriArguments
.
For example, if you set the value to prompt=consent&ui_locales=en
, it will be contained in the final authentication query.
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
.