我正在尝试替换过时的IdentityServer方法和类型,并且正如我所警告过的那样,我试图用适当的方法替换from contextlib import contextmanager
from django.core.cache import cache
@contextmanager
def memcache_lock(lock_name):
status = cache.add(lock_name, 'lock')
try:
yield status
finally:
cache.delete(lock_name)
@task()
def async_work(info):
with memcache_lock('my_lock_name') as acquired:
do_some_work()
和DiscoveryClient()
,例如最新的身份服务器{{ 3}}。当我尝试通过TokenClient()
获取相关端点时,即使我可以使用当前代码读取这些值并在浏览器上获取这些值,它也会返回null。
此外,由于未找到异常,当我绕过发现和提供直接令牌端点GetDiscoveryDocumentAsync
的步骤时,返回null。
为清楚起见,我应该说我没有更改我的身份服务器项目(尝试从中获取访问令牌)中的任何内容(其设置或端点)。
以下是我以前的和更新的代码,可以实现我所描述的内容。任何帮助或建议,表示赞赏。预先感谢。
以前的代码(有效):
RequestTokenAsync
更新的代码(不起作用):
var testServer = new TestServer(builder);
var client = testServer.CreateClient();
client.BaseAddress = new Uri("http://localhost:5000");
var discoClient = new DiscoveryClient(AuthorityUrl) {Policy = {RequireHttps = false}};
var disco = discoClient.GetAsync().Result;
var tokenClient = new TokenClient(disco.TokenEndpoint, ClientId, ClientSecret);
var tokenResponse = tokenClient.RequestClientCredentialsAsync(Scope).Result;
client.SetBearerToken(tokenResponse.AccessToken);
编辑:
如下所示更新了我的代码,仍然出现相同的错误。
var testServer = new TestServer(builder);
var client = testServer.CreateClient();
client.BaseAddress = new Uri("http://localhost:5000");
//var discoClient = new DiscoveryClient(AuthorityUrl) {Policy = {RequireHttps = false}};
var disco = client.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest()
{ Address = AuthorityUrl, Policy = new DiscoveryPolicy() { RequireHttps = false, Authority = AuthorityUrl} }).Result;
;
if (disco.IsError)
{
throw new Exception(disco.Error);
}
//var tokenClient = new TokenClient(disco.TokenEndpoint, ClientId, ClientSecret);
var tokenClient = client.RequestTokenAsync(new TokenRequest()
{ Address = disco.TokenEndpoint, ClientId = ClientId, ClientSecret = ClientSecret, GrantType = GrantType}).Result;
//var tokenResponse = tokenClient.RequestClientCredentialsAsync(Scope).Result;
client.SetBearerToken(tokenClient.AccessToken);
return client;
错误:
“连接到
var testServer = new TestServer(builder); var client = testServer.CreateClient(); client.BaseAddress = new Uri("http://localhost:5000"); //var discoClient = new DiscoveryClient(AuthorityUrl) {Policy = {RequireHttps = false}}; var disco = await client.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest() { Address = AuthorityUrl, Policy = new DiscoveryPolicy() { RequireHttps = false, Authority = AuthorityUrl } }); ; if (disco.IsError) { throw new Exception(disco.Error); } //var tokenClient = new TokenClient(disco.TokenEndpoint, ClientId, ClientSecret); var tokenClient =await client.RequestTokenAsync(new ClientCredentialsTokenRequest() { Address = disco.TokenEndpoint, ClientId = ClientId, ClientSecret = ClientSecret, GrantType = GrantType , Scope = Scope}); client.SetBearerToken(tokenClient.AccessToken); return client;
/。众所周知/ openid-配置时出错:未找到”