我想通过调用由 IS 验证的单独 api 将电子邮件服务与身份服务器项目分开。
我的问题是从身份服务器调用 api。目前,我在 IdentityServer 中有额外的“假”客户端正在调用 api。
这是客户端凭据流程的标准选项。
但我想省略客户端。所以IdentityServer是客户端。我在 IS 内部创建了一个“假”客户端,我认为这是错误的做法?
IdentityServer 内的 MessageService.cs
// Authenticating the fake client
var disco = await DiscoveryClient.GetAsync("http://localhost:5000");
var tokenClient = new TokenClient(disco.TokenEndpoint, "MailApiClient", "secret");
var tokenResponse = await tokenClient.RequestClientCredentialsAsync("EmailScope");
// Setting the token
client.SetBearerToken(tokenResponse.AccessToken);
var content = new StringContent(JsonConvert.SerializeObject(someMailModel));
// Posting to api
var response = await client.PostAsync(_emailSettings.RequestUri, content).ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
假客户端通过 IS 进行身份验证,然后将带有令牌的消息发送到 mailapi。我希望 IS 本身就是客户端,而不是在 IS 内部创建假客户端。因此IdentityServer将在没有中间件客户端的情况下调用api。
将来其他一些客户端也将使用 MailApi。
有一个类“IdentityServerTools”,它提供了在 IdentityServer 内手动颁发令牌的能力。
如何保护 IdentityServer4 调用的 Web API https://identityserver4.readthedocs.io/en/release/topics/tools.html
| 归档时间: |
|
| 查看次数: |
1815 次 |
| 最近记录: |