【问题标题】:identity server 4, Asp.net identity and身份服务器 4、Asp.net 身份和
【发布时间】:2020-11-17 14:20:28
【问题描述】:

我正在尝试将身份服务器4与asp.net身份集成,文档非常好https://identityserver4.readthedocs.io/en/latest/quickstarts/6_aspnet_identity.html

但我希望能够在不通过登录页面的情况下建立连接,而是在传递参数的同时通过简单的 GET 进行直接访问。

我发现这篇文章:https://damienbod.com/2017/04/14/asp-net-core-identityserver4-resource-owner-password-flow-with-custom-userrepository/

用这个方法

var response = await _httpClient.RequestPasswordTokenAsync(new PasswordTokenRequest
{
    Address = _disco.TokenEndpoint,

    ClientId = "resourceownerclient",
    ClientSecret = "dataEventRecordsSecret",
    Scope = "email openid dataEventRecords offline_access",

    UserName = user,
    Password = password
});

但不能让它与 Postman 一起工作

我有一个“invalid_request”错误

这是客户的声明:

new Client
{
    ClientId = "resourceownerclient",

    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
    AccessTokenType = AccessTokenType.Jwt,
    AccessTokenLifetime = 3600,
    IdentityTokenLifetime = 3600,
    UpdateAccessTokenClaimsOnRefresh = true,
    SlidingRefreshTokenLifetime = 30,
    AllowOfflineAccess = true,
    RefreshTokenExpiration = TokenExpiration.Absolute,
    RefreshTokenUsage = TokenUsage.OneTimeOnly,
    AlwaysSendClientClaims = true,
    Enabled = true,
    ClientSecrets=  new List<Secret> { new Secret("dataEventRecordsSecret".Sha256()) },
    AllowedScopes = {
        IdentityServerConstants.StandardScopes.OpenId, 
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email,
        IdentityServerConstants.StandardScopes.OfflineAccess,
        "dataEventRecords"
    },
    AllowAccessTokensViaBrowser=true
}

以这种方式使用 Asp.net Identity 的推荐方法是什么?

【问题讨论】:

    标签: asp.net-core asp.net-identity postman identityserver4


    【解决方案1】:

    您的邮递员请求中缺少grant_type

    POST /connect/token
    
        client_id=resourceownerclient&
        client_secret=dataEventRecordsSecret&
        grant_type=password&
        username=damienbod&
        password=damienbod&
        scope=email%20openid%20dataEventRecords%20offline_access
    

    不确定这是否是您遇到的唯一问题,但肯定是其中之一。如果这不是唯一的问题,身份服务器日志将包含有关请求问题的更多详细信息。

    【讨论】:

      猜你喜欢
      • 2017-07-26
      • 2017-12-22
      • 2019-03-24
      • 2019-09-24
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多