Skip to content

Commit 04874c1

Browse files
authored
Feature(sdk-auth): sdk auth login (#316)
* feat(login):add login model * refactor code
1 parent e0f07f3 commit 04874c1

File tree

3 files changed

+24
-3
lines changed
  • src
    • BuildingBlocks/StackSdks/Auth
    • Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service

3 files changed

+24
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class TokenModel
7+
{
8+
public string AccessToken { get; set; }
9+
10+
public string IdentityToken { get; set; }
11+
12+
public string RefreshToken { get; set; }
13+
14+
public int ExpiresIn { get; set; }
15+
}

src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface IUserService
7171

7272
Task<UserModel?> LoginByPhoneNumberAsync(LoginByPhoneNumberModel login);
7373

74-
Task<string> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login);
74+
Task<TokenModel> LoginByPhoneNumberFromSsoAsync(string address, LoginByPhoneNumberFromSso login);
7575

7676
Task RemoveUserRolesAsync(RemoveUserRolesModel user);
7777

src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public async Task<bool> UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user)
221221
return await _caller.PostAsync<UserModel>(requestUri, login);
222222
}
223223

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

245-
return tokenResponse.AccessToken;
245+
return new TokenModel
246+
{
247+
AccessToken = tokenResponse.AccessToken,
248+
IdentityToken = tokenResponse.IdentityToken,
249+
RefreshToken = tokenResponse.RefreshToken,
250+
ExpiresIn = tokenResponse.ExpiresIn,
251+
};
246252
}
247253

248254
public async Task RemoveUserRolesAsync(RemoveUserRolesModel user)

0 commit comments

Comments
 (0)