Skip to content

Commit

Permalink
Feature(sdk-auth): sdk auth login (#316)
Browse files Browse the repository at this point in the history
* feat(login):add login model

* refactor code
  • Loading branch information
wuweilaiya authored Oct 31, 2022
1 parent e0f07f3 commit 04874c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class TokenModel
{
public string AccessToken { get; set; }

public string IdentityToken { get; set; }

public string RefreshToken { get; set; }

public int ExpiresIn { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface IUserService

Task<UserModel?> LoginByPhoneNumberAsync(LoginByPhoneNumberModel login);

Task<string> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login);
Task<TokenModel> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login);

Task RemoveUserRolesAsync(RemoveUserRolesModel user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public async Task<bool> UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
return await _caller.PostAsync<UserModel>(requestUri, login);
}

public async Task<string> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login)
public async Task<TokenModel> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login)
{
using var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync(address);
Expand All @@ -242,7 +242,13 @@ public async Task<string> LoginByPhoneNumberFromSsoAsync(string address, LoginBy
if (tokenResponse.IsError)
throw new UserFriendlyException(tokenResponse.Error);

return tokenResponse.AccessToken;
return new TokenModel
{
AccessToken = tokenResponse.AccessToken,
IdentityToken = tokenResponse.IdentityToken,
RefreshToken = tokenResponse.RefreshToken,
ExpiresIn = tokenResponse.ExpiresIn,
};
}

public async Task RemoveUserRolesAsync(RemoveUserRolesModel user)
Expand Down

0 comments on commit 04874c1

Please sign in to comment.