public override Task <AuthRespondData> Auth(AuthRequestData request, ServerCallContext context)
 {
     return(Task.FromResult(new AuthRespondData
     {
         IsSucceed = true,
         AuthToken = Guid.NewGuid().ToString()
     }));
 }
예제 #2
0
        public async Task <ApiResponseResult <AuthResponse> > GetAuthResponse(AuthRequestData data)
        {
            var request = GetRequest(HttpMethod.Post, "auth");

            try
            {
                request.Content = GetJsonContent(data);

                using var response = await _client.SendAsync(request).ConfigureAwait(false);

                var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(ApiResponseResult <AuthResponse>(body, response.StatusCode));
            }
            catch (Exception e) when(e.IsApiCommunicationException())
            {
                throw new HttpRequestException(e.Message, e);
            }
        }
예제 #3
0
        public async Task <ApiResponseResult <AuthResponse> > AuthAsync(string username, string password)
        {
            var authData = new AuthRequestData
            {
                TwoFactorCode = "",
                GrantType     = "password",
                Username      = username,
                Password      = password
            };

            var response = await _apiClient.GetAuthResponse(authData);

            if (response.Success)
            {
                _userStorage.SaveUsername(username);
                _tokenStorage.AccessToken  = response.Value.AccessToken;
                _tokenStorage.RefreshToken = response.Value.RefreshToken;
            }

            return(response);
        }
예제 #4
0
        public async Task <ApiResponseResult <AuthResponse> > AuthAsync(string username, string password)
        {
            ApiResponseResult <AuthInfo> authInfo = await _apiClient.GetAuthInfoResponse(new AuthInfoRequestData
            {
                Username = username
            });

            if (!authInfo.Success)
            {
                return(ApiResponseResult <AuthResponse> .Fail(authInfo.StatusCode, authInfo.Error));
            }

            SrpPInvoke.GoProofs proofs   = SrpPInvoke.GenerateProofs(4, username, password, authInfo.Value.Salt, authInfo.Value.Modulus, authInfo.Value.ServerEphemeral);
            AuthRequestData     authData = new AuthRequestData
            {
                ClientEphemeral = Convert.ToBase64String(proofs.ClientEphemeral),
                ClientProof     = Convert.ToBase64String(proofs.ClientProof),
                SrpSession      = authInfo.Value.SrpSession,
                TwoFactorCode   = "",
                Username        = username
            };

            ApiResponseResult <AuthResponse> response = await _apiClient.GetAuthResponse(authData);

            if (response.Success)
            {
                if (!Convert.ToBase64String(proofs.ExpectedServerProof).Equals(response.Value.ServerProof))
                {
                    return(ApiResponseResult <AuthResponse> .Fail(0, "Invalid server proof."));
                }

                _userStorage.SaveUsername(username);
                _tokenStorage.Uid          = response.Value.Uid;
                _tokenStorage.AccessToken  = response.Value.AccessToken;
                _tokenStorage.RefreshToken = response.Value.RefreshToken;
            }

            return(response);
        }