コード例 #1
0
        /// <summary>
        /// Links the specified device to the user account. To enable authentication via device ID and linking, contact your Account Manager.
        /// </summary>
        /// <remarks>Swagger method name:<c>Link device to account</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/login-api/user-account/managed-by-client/devices/link-device-to-account/"/>.
        /// <param name="deviceType">Type of the device.</param>
        /// <param name="deviceName">Manufacturer and model name of the device.</param>
        /// <param name="deviceId">Device ID: For Android it is an ANDROID_ID constant. For iOS it is an identifierForVendor property.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void LinkDeviceToAccount(DeviceType deviceType, string deviceName, string deviceId, Action onSuccess = null, Action <Error> onError = null)
        {
            var deviceTypeAsString = deviceType.ToString().ToLower();
            var requestBody        = new LoginDeviceIdRequest(deviceName, deviceId);
            var url = string.Format(URL_DEVICES_LINKING, deviceTypeAsString);

            WebRequestHelper.Instance.PostRequest <LoginDeviceIdRequest>(SdkType.Login, url, requestBody, WebRequestHeader.AuthHeader(Token.Instance),
                                                                         onSuccess,
                                                                         onError);
        }
コード例 #2
0
        /// <summary>
        /// Authenticates a user via a particular device ID.
        /// </summary>
        /// <remarks> Swagger method name:<c>Auth via Device ID</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/login-api/auth/jwt/jwt-auth-via-device-id"/>.
        /// <see cref="https://developers.xsolla.com/login-api/auth/oauth-20/oauth-20-auth-via-device-id/"/>.
        /// <param name="deviceType">Type of the device.</param>
        /// <param name="deviceName">Manufacturer and model name of the device.</param>
        /// <param name="deviceId">Device ID: For Android it is an ANDROID_ID constant. For iOS it is an identifierForVendor property.</param>
        /// <param name="payload">Your custom data. The value of the parameter will be returned in the 'user JWT' > `payload` claim. Used only for JWT authorization type.</param>
        /// <param name="state">Value used for additional user verification. Often used to mitigate CSRF Attacks. The value will be returned in the response. Must be longer than 8 characters. Used only for OAuth2.0 authorization type.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void AuthViaDeviceID(DeviceType deviceType, string deviceName, string deviceId, string payload = null, string state = null, Action <string> onSuccess = null, Action <Error> onError = null)
        {
            var deviceTypeAsString = deviceType.ToString().ToLower();
            var requestBody        = new LoginDeviceIdRequest(deviceName, deviceId);

            if (XsollaSettings.AuthorizationType == AuthorizationType.JWT)
            {
                JwtAuthViaDeviceID(deviceTypeAsString, requestBody, payload, onSuccess, onError);
            }
            else             /*if (XsollaSettings.AuthorizationType == AuthorizationType.OAuth2_0)*/
            {
                OAuthAuthViaDeviceID(deviceTypeAsString, requestBody, state, onSuccess, onError);
            }
        }
コード例 #3
0
        private void JwtAuthViaDeviceID(string deviceType, LoginDeviceIdRequest requestBody, string payload = null, Action <string> onSuccess = null, Action <Error> onError = null)
        {
            var projectId       = XsollaSettings.LoginId;
            var payloadUrlParam = (payload != null) ? $"&payload={payload}" : string.Empty;
            var with_logout     = XsollaSettings.JwtTokenInvalidationEnabled ? "1" : "0";

            var url = string.Format(URL_JWT_DEVICE_ID_AUTH, deviceType, projectId, payloadUrlParam, with_logout);

            WebRequestHelper.Instance.PostRequest <TokenEntity, LoginDeviceIdRequest>(SdkType.Login, url, requestBody,
                                                                                      onComplete: (response) =>
            {
                Token.Instance = Token.Create(response.token);
                onSuccess?.Invoke(Token.Instance);
            },
                                                                                      onError, Error.LoginErrors);
        }
コード例 #4
0
        private void OAuthAuthViaDeviceID(string deviceType, LoginDeviceIdRequest requestBody, string state = null, Action <string> onSuccess = null, Action <Error> onError = null)
        {
            var clientId      = XsollaSettings.OAuthClientId;
            var stateUrlParam = state ?? DEFAULT_OAUTH_STATE;

            var url = string.Format(URL_OAUTH_DEVICE_ID_AUTH, deviceType, clientId, stateUrlParam);

            WebRequestHelper.Instance.PostRequest <LoginJwtJsonResponse, LoginDeviceIdRequest>(SdkType.Login, url, requestBody,
                                                                                               onComplete: (response) =>
            {
                if (ParseUtils.TryGetValueFromUrl(response.login_url, ParseParameter.code, out string code))
                {
                    XsollaLogin.Instance.ExchangeCodeToToken(code, onSuccessExchange: token => onSuccess?.Invoke(token), onError: onError);
                }
                else
                {
                    onError?.Invoke(Error.UnknownError);
                }
            },
                                                                                               onError, Error.LoginErrors);
        }