我想通过调用由is进行身份验证的单独api,将电子邮件服务从identity server项目中分离出来。
我的问题是从identity server调用api。目前,我在IdentityServer中有另外一个调用api的“假”客户端。
下面是客户端凭据流的标准选项。
-
获取令牌
-
返回令牌
-
调用api
-
检查令牌
-
返回数据
但我想省略客户。因此,IdentityServer就是客户端。
我在内部创建了一个“假”客户,我认为这样做是错误的?
MessageService。cs内部IdentityServer
// 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);
假客户端使用IS进行身份验证,然后将带有令牌的消息发送到mailapi。
相反,在内部创建假客户机是我想要的,是客户机本身。因此,IdentityServer将在没有中间件客户端的情况下调用api。
此外,将来还会有其他一些客户端使用MailApi。