iml6yu.IdentityService.Client
1.0.2-beta250403001
This is a prerelease version of iml6yu.IdentityService.Client.
dotnet add package iml6yu.IdentityService.Client --version 1.0.2-beta250403001
NuGet\Install-Package iml6yu.IdentityService.Client -Version 1.0.2-beta250403001
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="iml6yu.IdentityService.Client" Version="1.0.2-beta250403001" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="iml6yu.IdentityService.Client" Version="1.0.2-beta250403001" />
<PackageReference Include="iml6yu.IdentityService.Client" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add iml6yu.IdentityService.Client --version 1.0.2-beta250403001
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: iml6yu.IdentityService.Client, 1.0.2-beta250403001"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=iml6yu.IdentityService.Client&version=1.0.2-beta250403001&prerelease
#tool nuget:?package=iml6yu.IdentityService.Client&version=1.0.2-beta250403001&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
说明
webapi的用法
- 注入认证中间件
//初始化配置信息
IdentityServiceClientOption? idOption = builder.Configuration.GetSection("IdentityService").Get<IdentityServiceClientOption>();
if(idOption != null)
{
//注入配置
builder.Services.AddIdentityClient(idOption);
}
- 启用认证
//启用认证
app.UseIdentityClient();
- 配置信息
//认证客户端配置
"IdentityService": {
//认证类型 0 账号密码;1 客户端模式(就是密钥授权);2 授权码模式
"IdentityType": 0,
//客户端ID
"ClientId": "iml6yu_test_code",
//客户端密钥
"ClientSecret": "test",
//认证地址
"AuthorityHost": "http://192.168.1.108:8500",
//作用域 取决于服务端给分配的作用域(一般一个项目的作用域是固定不变的)
"Scope": [ "iml6yu_test_api" ],
//是否开启Https验证 如果true则必须用https协议和证书
"RequireHttpsMetadata": false,
//认证框架名称,默认就是Bearer,可以根据自己需要进行设置
"AuthenticationScheme": "Bearer",
//授权码类型的配置信息,其他类型的不用配置
"AuthorizationCode": {
//重定向URL,就是伴随code回传给服务器认证后,服务器重定向的url
"RedirectUri": "xxx",
//Token携带方式,伴随重定向url携带的token,默认是cookie。可以设置 0 在url的查询字符串中,1在cookie中,2 在header中
"TokenParameterType": 1,
//获取code模式登录的地址
"SignInUrl": "url",
//错误页面
"ErrorPage": "url"
}
客户端用法
- 授权码方式
IdentityServiceClient clientManager;
var option = new IdentityServiceClientOption()
{
AuthorityHost = "https://localhost:5001",
ClientId = "iml6yu_test_code",
ClientSecret = "test",
Scope = new List<string> { "iml6yu_test_api" },
IdentityType = IdentityType.AuthorizationCode,
Code = new AuthorizationCode()
{
RedirectUri = "https://localhost:5004"
}
};
var bearTokenValidator = new BearerTokenValidator(Microsoft.Extensions.Logging.LoggerFactory.Create(config => {
config.AddConsole();
}).CreateLogger<BearerTokenValidator>());
clientManager = new IdentityServiceClient(option, bearTokenValidator);
var result = await clientManager.LoginLocalAppWithoutApiServerAsync();
if (!result.State)
MessageBox.Show(result.Message + "\r\n--------------------------------------------\r\n" + result.Error.ToString());
else
MessageBox.Show(result.Datas?.AccessToken + "\r\n" + result.Datas?.RefreshToken + "\r\n" + result.Datas?.IdentityToken + "\r\n" + result.Datas?.Scope);
- 账号密码方式
IdentityServiceClient clientManager;
var option = new IdentityServiceClientOption()
{
AuthorityHost = "https://localhost:5001",
ClientId = "iml6yu_test_code",
ClientSecret = "test",
Scope = new List<string> { "iml6yu_test_api" },
IdentityType = IdentityType.ResourceOwerPassword
};
var bearTokenValidator = new BearerTokenValidator(Microsoft.Extensions.Logging.LoggerFactory.Create(config => {
config.AddConsole();
}).CreateLogger<BearerTokenValidator>());
clientManager = new IdentityServiceClient(option, bearTokenValidator);
var result = await clientManager.LoginAsync(new ResourceOwerPassword()
{
Password = "iml6yu.Admin",
UserName = "admin"
});
if (!result.State)
MessageBox.Show(result.Message + "\r\n--------------------------------------------\r\n" + result.Error.ToString());
else
MessageBox.Show(result.Datas.AccessToken + "\r\n" + result.Datas.RefreshToken + "\r\n" + result.Datas.IdentityToken + "\r\n" + result.Datas.Scope);
- 密钥方式登录
IdentityServiceClient clientManager;
var option = new IdentityServiceClientOption()
{
AuthorityHost = "https://localhost:5001",
ClientId = "iml6yu_test_client",
ClientSecret = "test",
Scope = new List<string> { "iml6yu_test_api" },
IdentityType = IdentityType.ClientCredentials
};
clientManager = new IdentityServiceClient(option);
var result = await clientManager.LoginAsync();
if (!result.State)
MessageBox.Show(result.Message + "\r\n--------------------------------------------\r\n" + result.Error?.ToString());
else
MessageBox.Show(result.Datas.AccessToken + "\r\n" + (result.Datas.RefreshToken ?? "no RefreshToken!!!") + "\r\n" + result.Datas.IdentityToken + "\r\n" + result.Datas.Scope);
Api 中用法
在controller中注入IdentityServiceClient
- 例子
[Route("api/[controller]")]
[ApiController]
public class LoginController : BaseController<LoginController>
{
IdentityServiceClient idClient;
public LoginController(BearerTokenValidator bearerTokenValidator, ILogger<LoginController> logger, IdentityServiceClient idClient) : base(bearerTokenValidator, logger)
{
this.idClient = idClient;
}
[AllowAnonymous]
[HttpGet]
public async Task<DataResult<TokenResponse>> Login(string username, string password)
{
var result = await idClient.LoginAsync(new ResourceOwerPassword() { Password = password, UserName = username });
return result;
}
}
AppBrowserScheme(.net6 ^+^ )
通过注册自定义浏览器协议,可以唤起本地app。 目前仅支持windows
注册框架
AppBrowserScheme.RegistBrowserScheme("框架名称,默认是iml6yu");
注销框架
AppBrowserScheme.UnRegistBrowserScheme("框架名称,默认是iml6yu");
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- IdentityModel (>= 7.0.0)
- IdentityModel.OidcClient (>= 6.0.0)
- iml6yu.IdentityService.Contracts (>= 1.0.1-beta240911001)
- iml6yu.Results (>= 1.0.4)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 6.0.31)
- Microsoft.AspNetCore.Hosting (>= 2.1.1)
- Microsoft.AspNetCore.Http (>= 2.1.34)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.AspNetCore.Server.Kestrel (>= 2.1.3)
- Microsoft.AspNetCore.Server.Kestrel.Core (>= 2.1.25)
- Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets (>= 2.1.40)
- System.IO.Pipelines (>= 8.0.0)
-
net8.0
- IdentityModel (>= 7.0.0)
- IdentityModel.OidcClient (>= 6.0.0)
- iml6yu.IdentityService.Contracts (>= 1.0.1-beta240911001)
- iml6yu.Results (>= 1.0.4)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.6)
- Microsoft.AspNetCore.Hosting (>= 2.1.1)
- Microsoft.AspNetCore.Http (>= 2.1.34)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.1.1)
- Microsoft.AspNetCore.Server.Kestrel (>= 2.1.3)
- Microsoft.AspNetCore.Server.Kestrel.Core (>= 2.1.25)
- Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets (>= 2.1.40)
- System.IO.Pipelines (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2-beta250403001 | 120 | 4/2/2025 |
1.0.2-beta250402001 | 116 | 4/2/2025 |