Ejemplo n.º 1
0
        /// <summary>
        /// Completes authentication by the user email address and a confirmation code.
        /// </summary>
        /// <see cref="https://developers.xsolla.com/login-api/auth/oauth-20/oauth-20-complete-auth-by-email/"/>
        /// <param name="email">User email address.</param>
        /// <param name="confirmationCode">Confirmation code.</param>
        /// <param name="operationId">ID of the confirmation code.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void OAuthCompleteAuthByEmail(string email, string confirmationCode, string operationId, Action <string> onSuccess, Action <Error> onError = null)
        {
            var data = new CompleteAuthByEmailRequest(email, confirmationCode, operationId);
            var url  = string.Format(URL_OAUTH_COMPLETE_AUTH_BY_EMAIL, XsollaSettings.OAuthClientId);

            WebRequestHelper.Instance.PostRequest <CompleteAuthByEmailResponse, CompleteAuthByEmailRequest>(
                SdkType.Login,
                url,
                data,
                response =>
            {
                if (ParseUtils.TryGetValueFromUrl(response.login_url, ParseParameter.code, out var parsedCode))
                {
                    ExchangeCodeToToken(parsedCode, token => onSuccess?.Invoke(token), onError);
                }
                else
                {
                    onError?.Invoke(Error.UnknownError);
                }
            },
                onError,
                Error.LoginErrors);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Completes authentication by the user email address and a confirmation code.
        /// </summary>
        /// <see cref="https://developers.xsolla.com/login-api/auth/jwt/jwt-complete-auth-by-email/"/>
        /// <param name="email">User email address.</param>
        /// <param name="confirmationCode">Confirmation code.</param>
        /// <param name="operationId">ID of the confirmation code.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void JwtCompleteAuthByEmail(string email, string confirmationCode, string operationId, Action <string> onSuccess, Action <Error> onError = null)
        {
            var data = new CompleteAuthByEmailRequest(email, confirmationCode, operationId);
            var url  = string.Format(URL_JWT_COMPLETE_AUTH_BY_EMAIL, XsollaSettings.LoginId);

            WebRequestHelper.Instance.PostRequest <CompleteAuthByEmailResponse, CompleteAuthByEmailRequest>(
                SdkType.Login,
                url,
                data,
                response =>
            {
                if (ParseUtils.TryGetValueFromUrl(response.login_url, ParseParameter.token, out var parsedToken))
                {
                    Token.Instance = Token.Create(parsedToken);
                    onSuccess?.Invoke(Token.Instance);
                }
                else
                {
                    onError?.Invoke(Error.UnknownError);
                }
            },
                onError,
                Error.LoginErrors);
        }