-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from masastack/feature/wasm
🆕 feat: support wasm
- Loading branch information
Showing
90 changed files
with
3,173 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ldingBlocks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SecurityTokenModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; | ||
|
||
public class SecurityTokenModel | ||
{ | ||
public string Region { get; set; } | ||
|
||
public string AccessKeyId { get; set; } | ||
|
||
public string AccessKeySecret { get; set; } | ||
|
||
public string StsToken { get; set; } | ||
|
||
public string Bucket { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/BuildingBlocks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IOssService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Masa.BuildingBlocks.StackSdks.Auth.Service; | ||
|
||
public interface IOssService | ||
{ | ||
Task<SecurityTokenModel> GetSecurityTokenAsync(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/BuildingBlocks/Dcc/Masa.BuildingBlocks.StackSdks.Dcc/Service/IOpenApiService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Masa.BuildingBlocks.StackSdks.Dcc.Service; | ||
|
||
public interface IOpenApiService | ||
{ | ||
Task<T> GetPublicConfigAsync<T>(string configObject, string environment = "", string cluster = "") where T : class, new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Config/_Imports.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
global using Masa.BuildingBlocks.Data.Contracts; | ||
global using Masa.BuildingBlocks.StackSdks.Config; | ||
global using Masa.BuildingBlocks.StackSdks.Config.Models; | ||
global using System.Security.Cryptography; | ||
global using System.Text; | ||
global using System.Text; |
36 changes: 36 additions & 0 deletions
36
src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/AuthClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.StackSdks.Auth; | ||
|
||
public class AuthClient : IAuthClient | ||
{ | ||
public AuthClient(ICaller caller, IMultiEnvironmentUserContext userContext) | ||
{ | ||
UserService = new UserService(caller, userContext); | ||
SubjectService = new SubjectService(caller); | ||
TeamService = new TeamService(caller, userContext); | ||
ProjectService = new ProjectService(caller, userContext); | ||
PermissionService = new PermissionService(caller, userContext); | ||
CustomLoginService = new CustomLoginService(caller); | ||
ThirdPartyIdpService = new ThirdPartyIdpService(caller); | ||
OssService = new OssService(caller); | ||
} | ||
|
||
public IUserService UserService { get; } | ||
|
||
public ISubjectService SubjectService { get; } | ||
|
||
public ITeamService TeamService { get; } | ||
|
||
public IPermissionService PermissionService { get; } | ||
|
||
public IProjectService ProjectService { get; } | ||
|
||
public ICustomLoginService CustomLoginService { get; } | ||
|
||
public IThirdPartyIdpService ThirdPartyIdpService { get; } | ||
|
||
public IOssService OssService { get; } | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Constants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.StackSdks.Auth; | ||
|
||
public static class Constants | ||
{ | ||
public const string DEFAULT_CLIENT_NAME = "masa.contrib.basicability.auth"; | ||
public const string DEFAULT_SSO_CLIENT_NAME = "masa.contrib.basicability.auth.sso"; | ||
public const string DEFAULT_SUBSCRIBE_KEY_PREFIX = "masa.auth:"; | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Masa.Contrib.StackSdks.Auth.Wasm.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="IdentityModel" Version="$(IdentityModelPackageVersion)" /> | ||
<PackageReference Include="Masa.BuildingBlocks.Authentication.OpenIdConnect.Models" Version="$(MasaFrameworkPackageVersion)" /> | ||
<PackageReference Include="Masa.BuildingBlocks.Authentication.Identity" Version="$(MasaFrameworkPackageVersion)" /> | ||
<ProjectReference Include="..\..\BuildingBlocks\Auth\Masa.BuildingBlocks.StackSdks.Auth\Masa.BuildingBlocks.StackSdks.Auth.csproj" /> | ||
<ProjectReference Include="..\Masa.Contrib.StackSdks.Caller.Wasm\Masa.Contrib.StackSdks.Caller.Wasm.csproj" /> | ||
<ProjectReference Include="..\Masa.Contrib.StackSdks.Isolation.Wasm\Masa.Contrib.StackSdks.Isolation.Wasm.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
20 changes: 20 additions & 0 deletions
20
src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/CustomLoginService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.StackSdks.Auth.Service; | ||
|
||
public class CustomLoginService : ICustomLoginService | ||
{ | ||
readonly ICaller _caller; | ||
|
||
public CustomLoginService(ICaller caller) | ||
{ | ||
_caller = caller; | ||
} | ||
|
||
public async Task<CustomLoginModel?> GetCustomLoginByClientIdAsync(string environment, string clientId) | ||
{ | ||
var requestUri = $"api/sso/customLogin/getByClientId"; | ||
return await _caller.GetAsync<object, CustomLoginModel>(requestUri, new { environment, clientId }); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
src/Contrib.Wasm/Masa.Contrib.StackSdks.Auth.Wasm/Service/LoginService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the MIT License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Contrib.StackSdks.Auth.Service; | ||
|
||
public class LoginService : ILoginService | ||
{ | ||
readonly IHttpClientFactory _httpClientFactory; | ||
|
||
public LoginService(IHttpClientFactory httpClientFactory) | ||
{ | ||
_httpClientFactory = httpClientFactory; | ||
} | ||
|
||
public async Task<TokenModel> LoginByPasswordAsync(LoginByPasswordModel login) | ||
{ | ||
var httpClient = CreateHttpClient(); | ||
var request = new PasswordTokenRequest() | ||
{ | ||
ClientId = login.ClientId, | ||
ClientSecret = login.ClientSecret, | ||
GrantType = GrantType.RESOURCE_OWNER_PASSWORD, | ||
UserName = login.Account, | ||
Password = login.Password, | ||
Scope = string.Join(' ', login.Scope), | ||
}; | ||
var tokenResponse = await httpClient.RequestPasswordTokenAsync(request); | ||
|
||
return ToModel(tokenResponse); | ||
} | ||
|
||
public async Task<TokenModel> LoginByPhoneNumberAsync(LoginByPhoneNumberFromSsoModel login) | ||
{ | ||
var client = CreateHttpClient(); | ||
|
||
var paramter = new Dictionary<string, string> | ||
{ | ||
["client_Id"] = login.ClientId, | ||
["client_secret"] = login.ClientSecret, | ||
["grant_type"] = GrantType.PHONE_CODE, | ||
["scope"] = string.Join(' ', login.Scope), | ||
["PhoneNumber"] = login.PhoneNumber, | ||
["code"] = login.Code | ||
}; | ||
|
||
var tokenResponse = await RequestTokenRawAsync(client, paramter); | ||
|
||
return ToModel(tokenResponse); | ||
} | ||
|
||
public async Task<LoginByThirdPartyIdpResultModel> LoginByThirdPartyIdpAsync(LoginByThirdPartyIdpModel login) | ||
{ | ||
var client = CreateHttpClient(); | ||
|
||
var paramter = new Dictionary<string, string> | ||
{ | ||
["client_Id"] = login.ClientId, | ||
["client_secret"] = login.ClientSecret, | ||
["grant_type"] = GrantType.THIRD_PARTY_IDP, | ||
["scope"] = string.Join(' ', login.Scope), | ||
["scheme"] = login.Scheme, | ||
["code"] = login.Code ?? "", | ||
["idToken"] = login.IdToken ?? "", | ||
}; | ||
|
||
var tokenResponse = await RequestTokenRawAsync(client, paramter); | ||
var tokenModel = ToModel(tokenResponse); | ||
var thirdPartyUser = tokenResponse.Json.GetProperty("thirdPartyUserData").Deserialize<ThirdPartyIdentityModel>(); | ||
var registerSuccess = tokenResponse.Json.TryGetBoolean("registerSuccess"); | ||
|
||
return new LoginByThirdPartyIdpResultModel | ||
{ | ||
ThirdPartyIdpLoginResultType = registerSuccess is true ? ThirdPartyIdpLoginResultTypes.Success : ThirdPartyIdpLoginResultTypes.NotRegister, | ||
Token = tokenModel, | ||
ThirdPartyIdentity = thirdPartyUser | ||
}; | ||
} | ||
|
||
public async Task<TokenModel> LoginByLdapAsync(LoginByLdapModel login) | ||
{ | ||
var client = CreateHttpClient(); | ||
|
||
var paramter = new Dictionary<string, string> | ||
{ | ||
["client_Id"] = login.ClientId, | ||
["client_secret"] = login.ClientSecret, | ||
["grant_type"] = GrantType.LDAP, | ||
["scope"] = string.Join(' ', login.Scope), | ||
["userName"] = login.UserName, | ||
["scheme"] = login.Scheme | ||
}; | ||
|
||
var tokenResponse = await RequestTokenRawAsync(client, paramter); | ||
|
||
return ToModel(tokenResponse); | ||
} | ||
|
||
HttpClient CreateHttpClient() | ||
{ | ||
return _httpClientFactory.CreateClient(DEFAULT_SSO_CLIENT_NAME); | ||
} | ||
|
||
static async Task<DiscoveryDocumentResponse> GetDiscoveryDocumentAsync(HttpClient httpClient) | ||
{ | ||
var disco = await httpClient.GetDiscoveryDocumentAsync(); | ||
if (disco.IsError) | ||
throw new UserFriendlyException(disco.Error); | ||
|
||
return disco; | ||
} | ||
|
||
static async Task<TokenResponse> RequestTokenRawAsync(HttpClient httpClient, Dictionary<string, string> paramter) | ||
{ | ||
var disco = await GetDiscoveryDocumentAsync(httpClient); | ||
var tokenResponse = await httpClient.RequestTokenRawAsync(disco.TokenEndpoint, new Parameters(paramter)); | ||
|
||
return tokenResponse; | ||
} | ||
|
||
static TokenModel ToModel(TokenResponse tokenResponse) | ||
{ | ||
if (tokenResponse.IsError) | ||
throw new UserFriendlyException(tokenResponse.Error); | ||
|
||
return new TokenModel | ||
{ | ||
AccessToken = tokenResponse.AccessToken, | ||
IdentityToken = tokenResponse.IdentityToken, | ||
RefreshToken = tokenResponse.RefreshToken, | ||
ExpiresIn = tokenResponse.ExpiresIn, | ||
}; | ||
} | ||
} |
Oops, something went wrong.