- Home /
Google+ authentication android
Hi!
I want my users to be able to login using their google account every time at app startup, until user decides to logout. I managed to do that using tokens:
// Set login info.
service = new SpreadsheetsService("app-name");
// Create OAuth2 Parameters.
oAuthParams = new OAuth2Parameters();
oAuthParams.ClientId = CLIENT_ID;
oAuthParams.ClientSecret = CLIENT_SECRET;
oAuthParams.RedirectUri = REDIRECT_URI;
oAuthParams.Scope = SCOPE;
public void Authenticate()
{
// Open web browser for user to authenticate.
string authUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(oAuthParams);
Application.OpenURL(authUrl);
}
public bool FinishAuthenticate(string accessCode)
{
// Save access code.
oAuthParams.AccessCode = accessCode;
try
{
// Get access token.
OAuthUtil.GetAccessToken(oAuthParams);
myToken = oAuthParams.AccessToken;
PlayerPrefs.SetString ("myToken", myToken);
mySecretToken = oAuthParams.ClientSecret;
PlayerPrefs.SetString ("mySecretToken", mySecretToken);
myRefreshToken = oAuthParams.RefreshToken;
PlayerPrefs.SetString ("myRefreshToken", myRefreshToken);
// Save data to make authorized requests.
GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "app-name", oAuthParams);
service.RequestFactory = requestFactory;
myUserName = GetUserName ();
logged = true;
return true;
}
catch (WebException)
{
return false;
}
}
and that works perfect in standalone, but I want to use the phone's google accounts on android, so the user will not be redirected to the web browser and copy the key.
Is that possible in unity? I searched a while but could not find a proper solution for this.
Comment
Your answer
Follow this Question
Related Questions
[RESOLVED] Google Project Tango - Unity Integration 2 Answers
When I start my game on Android this crashes (google play problem) 0 Answers
Opening External Login Page 0 Answers
How to integrate new google play games services for leaderboard? 2 Answers
Video system / rendering is stuck on Android OculusGO 0 Answers