private void ProcessOAuthResponse(LoginOAuthJsonResponse response, Action <string> onSuccessToken = null) { Debug.Log("OAuth response received"); Token.Instance = Token.Create(response.access_token); SaveToken(Constants.LAST_SUCCESS_AUTH_TOKEN, response.access_token); PlayerPrefs.SetString(Constants.LAST_SUCCESS_OAUTH_REFRESH_TOKEN, response.refresh_token); //Set expiration time for expiration check on next application start var expirationTime = DateTime.Now.AddSeconds(response.expires_in); PlayerPrefs.SetString(Constants.OAUTH_REFRESH_TOKEN_EXPIRATION_TIME, expirationTime.ToString()); //Set next token refresh while application active SetRefreshAfter(response.expires_in); IsOAuthTokenRefreshInProgress = false; onSuccessToken?.Invoke(response.access_token); }
private void TryRefreshAndroidSocial() { using (var helper = new AndroidSDKSocialAuthHelper()) { if (!helper.IsRefreshSocialTokenPossible) { Debug.Log("Android social token refresh is not available at the moment"); IsOAuthTokenRefreshInProgress = false; return; } Action <string> onSuccessRefresh = newToken => { var surrogateResponse = new LoginOAuthJsonResponse() { access_token = newToken, expires_in = ANDROID_TOKEN_REFRESH_RATE, refresh_token = string.Empty, }; ProcessOAuthResponse(surrogateResponse); }; Action <Error> onError = error => { if (error != null) { Debug.LogError(error.errorMessage); } IsOAuthTokenRefreshInProgress = false; }; IsOAuthTokenRefreshInProgress = helper.TryRefreshSocialToken(onSuccessRefresh, onError); } }