forked from dotnetcore/WebApiClient
-
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.
修改所有TokenProvider实现ITokenProvider<>;
修改所有TokenProvider注册为ITokenProvider<>; 增加ICustomTokenProvider和CustomTokenClient; 增加添加自定义TokenClient的服务注册扩展; 修改OAuthTokenAttribute为非抽象类;
- Loading branch information
Showing
33 changed files
with
385 additions
and
621 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
13 changes: 9 additions & 4 deletions
13
WebApiClientCore.Extensions.OAuths/Attributes/ClientCredentialsTokenAttribute.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,23 +1,28 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using WebApiClientCore.Exceptions; | ||
using WebApiClientCore.Extensions.OAuths; | ||
|
||
namespace WebApiClientCore.Attributes | ||
{ | ||
/// <summary> | ||
/// 表示client_credentials授权方式的token应用特性 | ||
/// 表示由client模式token提供者提供的token应用特性 | ||
/// 需要注册services.AddClientCredentialsTokenProvider | ||
/// </summary> | ||
public class ClientCredentialsTokenAttribute : OAuthTokenAttribute | ||
{ | ||
/// <summary> | ||
/// 获取token提供者 | ||
/// </summary> | ||
/// <param name="context">上下文</param> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
protected override ITokenProvider GetTokenProvider(ApiRequestContext context) | ||
{ | ||
var providerType = typeof(IClientCredentialsTokenProvider<>).MakeGenericType(context.ApiAction.InterfaceType); | ||
return (ITokenProvider)context.HttpContext.ServiceProvider.GetRequiredService(providerType); | ||
var provider = base.GetTokenProvider(context); | ||
if (provider.ProviderType != ProviderType.ClientCredentials) | ||
{ | ||
throw new ApiInvalidConfigException($"未注册{nameof(TokenProviderExtensions.AddClientCredentialsTokenProvider)}"); | ||
} | ||
return provider; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
WebApiClientCore.Extensions.OAuths/Attributes/CustomTokenAttribute.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,28 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using WebApiClientCore.Exceptions; | ||
using WebApiClientCore.Extensions.OAuths; | ||
|
||
namespace WebApiClientCore.Attributes | ||
{ | ||
/// <summary> | ||
/// 表示由自定义token提供者提供的token应用特性 | ||
/// 需要注册services.AddCustomTokenProvider | ||
/// </summary> | ||
public class CustomTokenAttribute : OAuthTokenAttribute | ||
{ | ||
/// <summary> | ||
/// 获取token提供者 | ||
/// </summary> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
protected override ITokenProvider GetTokenProvider(ApiRequestContext context) | ||
{ | ||
var provider = base.GetTokenProvider(context); | ||
if (provider.ProviderType != ProviderType.Custom) | ||
{ | ||
throw new ApiInvalidConfigException($"未注册{nameof(TokenProviderExtensions.AddCustomTokenProvider)}"); | ||
} | ||
return provider; | ||
} | ||
} | ||
} |
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
13 changes: 9 additions & 4 deletions
13
WebApiClientCore.Extensions.OAuths/Attributes/PasswordCredentialsTokenAttribute.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,23 +1,28 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using WebApiClientCore.Exceptions; | ||
using WebApiClientCore.Extensions.OAuths; | ||
|
||
namespace WebApiClientCore.Attributes | ||
{ | ||
/// <summary> | ||
/// 表示password授权方式的token应用特性 | ||
/// 表示由password模式token提供者提供的token应用特性 | ||
/// 需要注册services.AddPasswordCredentialsTokenProvider | ||
/// </summary> | ||
public class PasswordCredentialsTokenAttribute : OAuthTokenAttribute | ||
{ | ||
/// <summary> | ||
/// 获取token提供者 | ||
/// </summary> | ||
/// <param name="context">上下文</param> | ||
/// <param name="context"></param> | ||
/// <returns></returns> | ||
protected override ITokenProvider GetTokenProvider(ApiRequestContext context) | ||
{ | ||
var providerType = typeof(IPasswordCredentialsTokenProvider<>).MakeGenericType(context.ApiAction.InterfaceType); | ||
return (ITokenProvider)context.HttpContext.ServiceProvider.GetRequiredService(providerType); | ||
var provider = base.GetTokenProvider(context); | ||
if (provider.ProviderType != ProviderType.PasswordClientCredentials) | ||
{ | ||
throw new ApiInvalidConfigException($"未注册{nameof(TokenProviderExtensions.AddPasswordCredentialsTokenProvider)}"); | ||
} | ||
return provider; | ||
} | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
WebApiClientCore.Extensions.OAuths/HttpMessageHandlers/ClientCredentialsTokenHandler.cs
This file was deleted.
Oops, something went wrong.
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
34 changes: 0 additions & 34 deletions
34
WebApiClientCore.Extensions.OAuths/HttpMessageHandlers/PasswordCredentialsTokenHandler.cs
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
WebApiClientCore.Extensions.OAuths/IPasswordCredentialsTokenProvider.cs
This file was deleted.
Oops, something went wrong.
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: 3 additions & 3 deletions
6
...OAuths/IClientCredentialsTokenProvider.cs → ...Core.Extensions.OAuths/ITokenProvider`.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,10 +1,10 @@ | ||
namespace WebApiClientCore.Extensions.OAuths | ||
{ | ||
/// <summary> | ||
/// 定义Client身份信息token提供者的接口 | ||
/// 定义指定接口的token提供者的接口 | ||
/// </summary> | ||
/// <typeparam name="THttpApi"></typeparam> | ||
public interface IClientCredentialsTokenProvider<THttpApi> : ITokenProvider | ||
public interface ITokenProvider<THttpApi> : ITokenProvider | ||
{ | ||
} | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
...sions.OAuths/Microsoft.Extensions/DependencyInjection/IClientCredentialsOptionsBuilder.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.