public override void TryAuth(params object[] args) { if (TryExtractProvider(args, out SocialProvider provider)) { SetListener(); _requestedProvider = provider; try { using (var sdkHelper = new AndroidSDKSocialAuthHelper()) { sdkHelper.PerformSocialAuth(provider); } Debug.Log("AndroidSocialAuth.SocialNetworkAuth: auth request was sent"); } catch (Exception ex) { Debug.LogError($"AndroidSocialAuth.SocialNetworkAuth: {ex.Message}"); RemoveListener(); base.OnError?.Invoke(new Error(errorMessage: "Social auth failed")); } } else { Debug.LogWarning("AndroidSocialAuth.TryAuth: Could not extract argument"); base.OnError?.Invoke(new Error(errorMessage: "Social auth failed")); } }
/// <summary> /// Begins processing to update a list of user’s friends from a social provider. /// </summary> /// <remarks> Swagger method name:<c>Update User's Friends</c>.</remarks> /// <see cref="https://developers.xsolla.com/login-api/methods/users/update-users-friends/"/>. /// <param name="token">JWT from Xsolla Login.</param> /// <param name="provider">Name of social provider.</param> /// <param name="onSuccess">Success operation callback.</param> /// <param name="onError">Failed operation callback.</param> public void UpdateUserSocialFriends(string token, SocialProvider provider = SocialProvider.None, Action onSuccess = null, Action <Error> onError = null) { var providerUrlAddition = provider != SocialProvider.None ? $"?platform={provider.GetParameter()}" : string.Empty; var url = string.Format(URL_USER_UPDATE_SOCIAL_FRIENDS, providerUrlAddition); WebRequestHelper.Instance.PostRequest(SdkType.Login, url, WebRequestHeader.AuthHeader(token), onSuccess, onError); }
public bool IsScrobblingPossible(SocialProvider provider) { bool possible = false; ThrowHelper.ThrowIfError(LibSpotify.sp_session_is_scrobbling_possible_r(Handle, provider, ref possible)); return(possible); }
/// <summary> /// Get `url` for social authentication in browser. /// </summary> /// <remarks> Swagger method name:<c>Auth via Social Network</c>.</remarks> /// <see cref="https://developers.xsolla.com/login-api/jwt/jwt-auth-via-social-network/"/>. /// <param name="socialProvider">Name of social provider.</param> /// <param name="oauthState">Value used for additional user verification on backend. Must be at least 8 symbols long. Will be "xsollatest" by default.</param> /// <param name="payload">Custom data. The value of the parameter will be returned in the user JWT > payload claim (JWT only).</param> /// <param name="fields">List of parameters which should be requested from the user or social network additionally and written to the token (JWT only).</param> /// <see cref="https://developers.xsolla.com/login-api/methods/oauth-20/oauth-20-auth-via-social-network"/>. public string GetSocialNetworkAuthUrl(SocialProvider socialProvider, string oauthState = null, string payload = null, List <string> fields = null) { string result = default(string); switch (XsollaSettings.AuthorizationType) { case AuthorizationType.JWT: var projectId = XsollaSettings.LoginId; var with_logout = XsollaSettings.JwtTokenInvalidationEnabled ? "1" : "0"; var extra_fields = fields != null && fields.Any() ? string.Join(",", fields) : string.Empty; result = string.Format(URL_JWT_SOCIAL_AUTH, socialProvider.GetParameter(), projectId, with_logout, payload, extra_fields); break; case AuthorizationType.OAuth2_0: var socialNetwork = socialProvider.GetParameter(); var clientId = XsollaSettings.OAuthClientId.ToString(); var state = oauthState ?? DEFAULT_OAUTH_STATE; result = string.Format(URL_OAUTH_SOCIAL_AUTH, socialNetwork, clientId, state); break; default: Debug.LogError($"Unexpected authorization type: '{XsollaSettings.AuthorizationType}'"); return(null); } result = WebRequestHelper.Instance.AppendAnalyticsToUrl(SdkType.Login, result); return(result); }
private void SetSocialFriendship(SocialProvider provider) { if (provider != SocialProvider.None) { AddSocialFriendshipMark(provider); } }
private bool TryExtractProvider(object[] args, out SocialProvider provider) { provider = default(SocialProvider); if (args == null) { Debug.LogError("IosSocialAuth.TryExtractProvider: 'object[] args' was null"); return(false); } if (args.Length != 1) { Debug.LogError($"IosSocialAuth.TryExtractProvider: args.Length expected 1, was {args.Length}"); return(false); } try { provider = (SocialProvider)args[0]; } catch (Exception ex) { Debug.LogError($"IosSocialAuth.TryExtractProvider: Error during argument extraction: {ex.Message}"); return(false); } return(true); }
public ScrobblingState GetScrobbling(SocialProvider provider) { ScrobblingState state = ScrobblingState.GlobalDisabled; ThrowHelper.ThrowIfError(LibSpotify.sp_session_is_scrobbling_r(Handle, provider, ref state)); return(state); }
/// <summary> /// Links the social network, which is used by the player for authentication, to the user account. /// </summary> /// <remarks> Swagger method name:<c>Link Social Network To Account</c>.</remarks> /// <see cref="https://developers.xsolla.com/user-account-api/social-networks/link-social-network-to-account/"/>. /// <param name="socialProvider">Name of social provider.</param> /// <param name="urlCallback">Success operation callback.</param> /// <param name="onError">Failed operation callback.</param> public void LinkSocialProvider(SocialProvider socialProvider, Action <string> urlCallback, Action <Error> onError = null) { var redirectUrl = !string.IsNullOrEmpty(XsollaSettings.CallbackUrl) ? XsollaSettings.CallbackUrl : DEFAULT_REDIRECT_URI; var url = string.Format(URL_LINK_SOCIAL_NETWORK, socialProvider.GetParameter(), redirectUrl); WebRequestHelper.Instance.GetRequest <LinkSocialProviderResponse>(SdkType.Login, url, WebRequestHeader.AuthHeader(Token.Instance), response => urlCallback?.Invoke(response.url)); }
/// <summary> /// Gets user’s friends from social provider. /// </summary> /// <remarks> Swagger method name:<c>Get User's Friends</c>.</remarks> /// <see cref="https://developers.xsolla.com/login-api/methods/users/get-users-friends/"/>. /// <param name="token">JWT from Xsolla Login.</param> /// <param name="provider">Name of social provider.</param> /// <param name="offset">Offset.</param> /// <param name="limit">Limit.</param> /// <param name="withUid"></param> /// <param name="onSuccess">Successful operation callback.</param> /// <param name="onError">Failed operation callback.</param> public void GetUserSocialFriends(string token, SocialProvider provider = SocialProvider.None, uint offset = 0, uint limit = 500, bool withUid = false, Action <UserSocialFriends> onSuccess = null, Action <Error> onError = null) { var withUidFlag = withUid ? "true" : "false"; var providerUrlAddition = provider != SocialProvider.None ? $"&platform={provider.GetParameter()}" : string.Empty; var url = string.Format(URL_USER_SOCIAL_FRIENDS, offset, limit, withUidFlag, providerUrlAddition); WebRequestHelper.Instance.GetRequest(SdkType.Login, url, WebRequestHeader.AuthHeader(token), onSuccess, onError); }
public void AddSocialFriendshipMark(SocialProvider socialProvider) { SocialFriendship.SetActive(true); foreach (var marker in SocialFriendshipMarkers) { if (marker.SocialProvider == socialProvider) { marker.gameObject.SetActive(true); break; } } }
public void LinkSocialProvider(SocialProvider socialProvider, Action <SocialProvider> onSuccess, Action <Error> onError = null) { if (!EnvironmentDefiner.IsStandaloneOrEditor) { var errorMessage = "LinkSocialProvider: This functionality is not supported elswere except Editor and Standalone build"; Debug.LogError(errorMessage); onError?.Invoke(new Error(ErrorType.MethodIsNotAllowed, errorMessage: errorMessage)); return; } Action <string> urlCallback = url => { var browser = BrowserHelper.Instance.InAppBrowser; if (browser == null) { Debug.LogError("LinkSocialProvider: Can not obtain in-built browser"); onError?.Invoke(null); return; } browser.Open(url); browser.AddInitHandler(() => { browser.AddUrlChangeHandler(newUrl => { Debug.Log($"URL = {newUrl}"); if (ParseUtils.TryGetValueFromUrl(newUrl, ParseParameter.token, out _)) { browser.Close(); HotkeyCoroutine.Unlock(); onSuccess?.Invoke(socialProvider); return; } if (ParseUtils.TryGetValueFromUrl(newUrl, ParseParameter.error_code, out string errorCode) && ParseUtils.TryGetValueFromUrl(newUrl, ParseParameter.error_description, out string errorDescription)) { browser.Close(); HotkeyCoroutine.Unlock(); onError?.Invoke(new Error(statusCode: errorCode, errorMessage: errorDescription)); } }); }); }; XsollaLogin.Instance.LinkSocialProvider(socialProvider, urlCallback, onError); }
public Task LoginWithSocialAsync(SocialProvider provider) { try { oAuth2 = OAuth2ProviderFactory.CreateProvider(provider); var authenticator = new OAuth2Authenticator( oAuth2.ClientId, oAuth2.ClientSecret, oAuth2.Scope, oAuth2.AuthorizationUri, oAuth2.RedirectUri, oAuth2.RequestTokenUri, null, oAuth2.IsUsingNativeUI); App.Authenticator = authenticator; authenticator.Completed += async(s, e) => { if (e.IsAuthenticated) { // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var user = await oAuth2.GetUserInfoAsync(e.Account); MessagingCenter.Send(user, MessagingCenterKeys.AuthenticationRequested, true); Debug.WriteLine("Authentication Success"); } }; authenticator.Error += (s, e) => { Debug.WriteLine("Authentication error: " + e.Message); }; var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter(); presenter.Login(authenticator); } catch (Exception ex) { Debug.WriteLine("Login Error : " + ex.Message); return(Task.FromResult(false)); } return(Task.FromResult(true)); }
public static OAuth2Base CreateProvider(SocialProvider provider) { OAuth2Base oAuth2 = null; switch (provider) { case SocialProvider.Google: oAuth2 = GoogleOAuth2.Instance; break; case SocialProvider.Line: oAuth2 = LineOAuth2.Instance; break; case SocialProvider.Facebook: oAuth2 = FacebookOAuth2.Instance; break; } return(oAuth2); }
public void PerformSocialAuth(SocialProvider socialProvider) { var providerName = socialProvider.ToString().ToUpper(); Debug.Log($"Trying android social auth for '{providerName}'"); try { var unitySDKHelper = new AndroidJavaClass("com.xsolla.android.login.XLogin$Unity"); var actvity = _androidHelper.CurrentActivity; var socialNetworkClass = new AndroidJavaClass("com.xsolla.android.login.social.SocialNetwork"); var socialNetworkObject = socialNetworkClass.GetStatic <AndroidJavaObject>(providerName); var invalidationFlag = _invalidationFlag; unitySDKHelper.CallStatic("authSocial", actvity, socialNetworkObject, invalidationFlag); } catch (Exception ex) { throw new AggregateException($"AndroidSDKSocialAuthHelper.PerformSocialAuth: {ex.Message}", ex); } }
public void RunSocialAuth(SocialProvider socialProvider) { if (IsAuthInProgress) { return; } IsAuthInProgress = true; object[] args = { socialProvider }; Action <string> onSuccessfulSocialAuth = token => SdkLoginLogic.Instance .ValidateToken(token, t => CompleteSuccessfulAuth(token, isSaveToken: true), ProcessError); Action <Error> onFailedSocialAuth = ProcessError; #if UNITY_EDITOR || UNITY_STANDALONE TryAuthBy <SocialAuth>(args, onSuccessfulSocialAuth, onFailedSocialAuth); #elif UNITY_ANDROID TryAuthBy <AndroidSocialAuth>(args, onSuccessfulSocialAuth, onFailedSocialAuth); #elif UNITY_IOS TryAuthBy <IosSocialAuth>(args, onSuccessfulSocialAuth, onFailedSocialAuth); #endif }
public override void TryAuth(params object[] args) { if (TryExtractProvider(args, out SocialProvider provider)) { _requestedProvider = provider; try { var providerName = _requestedProvider.ToString().ToLower(); Action <string> onSuccessNative = SuccessHandler; Action <string> onErrorNative = FailHandler; Action onCancelNative = CancelHandler; #if UNITY_IOS _authBySocialNetwork(providerName, XsollaSettings.OAuthClientId, DEMO_AUTH_STATE, XsollaSettings.CallbackUrl, IosCallbacks.ActionStringCallback, onSuccessNative.GetPointer(), IosCallbacks.ActionStringCallback, onErrorNative.GetPointer(), IosCallbacks.ActionVoidCallback, onCancelNative.GetPointer()); Debug.Log("IosSocialAuth.SocialNetworkAuth: auth request was sent"); #else Debug.LogError("IosSocialAuth.TryAuth: Platform not supported"); base.OnError?.Invoke(new Error(errorMessage: "Social auth failed")); #endif } catch (Exception ex) { Debug.LogError($"IosSocialAuth.SocialNetworkAuth: {ex.Message}"); base.OnError?.Invoke(new Error(errorMessage: "Social auth failed")); } } else { Debug.LogError("IosSocialAuth.TryAuth: Could not extract argument"); base.OnError?.Invoke(new Error(errorMessage: "Social auth failed")); } }
public static string GetParameter(this SocialProvider provider) { switch (provider) { case SocialProvider.Facebook: return("facebook"); case SocialProvider.GitHub: return("github"); case SocialProvider.Google: return("google"); case SocialProvider.Twitch: return("twitch"); case SocialProvider.Twitter: return("twitter"); case SocialProvider.Steam: return("steam"); case SocialProvider.Xbox: return("xbox"); case SocialProvider.Discord: return("discord"); case SocialProvider.Vk: return("vk"); case SocialProvider.Naver: return("naver"); case SocialProvider.Kakao: return("kakao"); case SocialProvider.Baidu: return("baidu"); case SocialProvider.Battlenet: return("battlenet"); case SocialProvider.ChinaTelecom: return("chinatelecom"); case SocialProvider.Instagram: return("instagram"); case SocialProvider.LinkedIn: return("linkedin"); case SocialProvider.Odnoklassniki: return("ok"); case SocialProvider.PayPal: return("paypal"); case SocialProvider.Pinterest: return("pinterest"); case SocialProvider.QQ: return("qq"); case SocialProvider.Reddit: return("reddit"); case SocialProvider.Vimeo: return("vimeo"); case SocialProvider.WeChat: return("wechat"); case SocialProvider.Weibo: return("weibo"); case SocialProvider.Yahoo: return("yahoo"); case SocialProvider.Amazon: return("amazon"); case SocialProvider.Mailru: return("mailru"); case SocialProvider.Microsoft: return("microsoft"); case SocialProvider.Msn: return("msn"); case SocialProvider.Yandex: return("yandex"); case SocialProvider.YouTube: return("youtube"); case SocialProvider.Apple: return("apple"); default: throw new Exception(provider.ToString()); } }
private void NetworkOnStateChanged(SocialProvider socialProvider, FriendSystemSocialNetwork.State state) { SdkFriendsLogic.Instance.GetFriendsFromSocialNetworks(RefreshUsersContainer); }
public string GetSocialNetworkAuthUrl(SocialProvider socialProvider) { return(XsollaLogin.Instance.GetSocialNetworkAuthUrl(socialProvider)); }
private static void RunSocialAuthMethod(LoginPageEnterController loginController, object arg) { SocialProvider provider = (SocialProvider)arg; loginController.RunSocialAuth(provider); }
internal static extern Error sp_session_set_scrobbling(IntPtr sessionPtr, SocialProvider socialProvider, ScrobblingState scrobblingState);
internal static extern Error sp_session_set_social_credentials(IntPtr sessionPtr, SocialProvider socialProvider, string userName, string password);
public void SetScrobbling(SocialProvider provider, ScrobblingState state) { ThrowHelper.ThrowIfError(LibSpotify.sp_session_set_scrobbling_r(Handle, provider, state)); }
internal static extern Error sp_session_is_scrobbling_possible(IntPtr sessionPtr, SocialProvider socialProvider, out bool isPossible);
internal static extern Error sp_session_set_scrobbling(IntPtr sessionPtr, SocialProvider socialProvider, ScrobblingState scrobblingState);
private void RequestSocialAuth(SocialProvider provider) { ExecuteProxyRequest(LoginProxyActions.RunSocialAuthDelegate, provider); }
public void SetSocialCredentials(SocialProvider provider, string username, string password) { ThrowHelper.ThrowIfError(LibSpotify.sp_session_set_social_credentials_r(Handle, provider, username, password)); }
internal static extern bool sp_session_is_scrobbling(IntPtr sessionPtr, SocialProvider socialProvider, ScrobblingState scrobblingState);
internal static extern bool sp_session_is_scrobbling(IntPtr sessionPtr, SocialProvider socialProvider, ScrobblingState scrobblingState);
internal static extern Error sp_session_set_social_credentials(IntPtr sessionPtr, SocialProvider socialProvider, string userName, string password);
internal static extern Error sp_session_is_scrobbling_possible(IntPtr sessionPtr, SocialProvider socialProvider, out bool isPossible);