IdentityServer4 - RequestedClaimTypes пуст - PullRequest
       20

IdentityServer4 - RequestedClaimTypes пуст

0 голосов
/ 07 октября 2018

Из документации IdentityServer 4: Если запрошенные области являются ресурсами идентификации, то заявки в RequestedClaimTypes будут заполняться на основе типов заявок пользователя, определенных в IdentityResource

Этомой ресурс идентификации:

return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResources.Phone(),
                new IdentityResources.Email(),
                new IdentityResource(ScopeConstants.Roles, new List<string> { JwtClaimTypes.Role })
            };

, а это мой клиент

AllowedScopes = {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        IdentityServerConstants.StandardScopes.Phone,
                        IdentityServerConstants.StandardScopes.Email,
                        ScopeConstants.Roles
                    },

ProfileService - метод GetProfileDataAsync:

public async Task GetProfileDataAsync(ProfileDataRequestContext context)
    {
        var sub = context.Subject.GetSubjectId();
        var user = await _userManager.FindByIdAsync(sub);
        var principal = await _claimsFactory.CreateAsync(user);

        var claims = principal.Claims.ToList();
        claims = claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();

        if (user.Configuration != null)
            claims.Add(new Claim(PropertyConstants.Configuration, user.Configuration));

        context.IssuedClaims = claims;
    }

Principal.claims.ToList () имеетвсе утверждения перечислены, но context.RequestedClaimTypes пуст, следовательно, фильтр по context.RequestedClaimTypes.Contains (drug.Type)) не возвращает никаких утверждений.

Конфигурация клиента:

let header = new HttpHeaders({'Content-Type': 'application / x-www-form-urlencoded'});

let params = new HttpParams()
    .append('username', userName)
    .append('password', password)
    .append('grant_type', 'password')
    .append('scope', 'email offline_access openid phone profile roles api_resource')
    .append('resource', window.location.origin)
    .append('client_id', 'test_spa');

let requestBody = params.toString();

return this.http.post<T>(this.loginUrl, requestBody, { headers: header });

Тип ответа:

export interface LoginResponse {
    access_token: string;
    token_type: string;
    refresh_token: string;
    expires_in: number;
}

Кто-то указал, что добавление AlwaysIncludeUserClaimsInIdToken = true разрешаетпроблема - я пытался, и это не так.

Что мне здесь не хватает?Пожалуйста, помогите.

...