Skip to content

Add "user info" endpoint for the Delivery API#17719

Merged
elit0451 merged 2 commits intov13/devfrom
v13/feature/delivery-api-user-info-endpoint
Dec 9, 2024
Merged

Add "user info" endpoint for the Delivery API#17719
elit0451 merged 2 commits intov13/devfrom
v13/feature/delivery-api-user-info-endpoint

Conversation

@kjac
Copy link
Contributor

@kjac kjac commented Dec 4, 2024

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #17508

Description

This PR adds a "user info" endpoint to the Delivery API, to access basic information about authorized members. See the linked discussion for details on the motivation for adding this endpoint.

The "user info" endpoint is part of the OpenId Connect core spec.

This implementation returns a few of the standard claims, all of which are subject of availability:

  • sub (required claim)
  • name (if available)
  • email (if available)

On top of this, the member groups (if any) are returned in the role claim.

The implementation is build to be extendable, so custom claims can be added to these claims - and the core claims can be removed, too.

Testing this PR

To test this PR, authorized member access must be enabled and setup for the Delivery API - see the docs.

Verify that:

  1. The standard claims can be retrieved from the user info endpoint given a valid access token.
  2. The user info endpoint is not available without a valid access token.
  3. It is possible to extend the returned claims with a custom implementation of ICurrentMemberClaimsProvider (or a specialization of CurrentMemberClaimsProvider).
  4. The user info endpoint is listed under /.well-known/openid-configuration.
    image

Copy link
Contributor

@elit0451 elit0451 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests out great 💪 Merging

@elit0451 elit0451 merged commit ee8bdfc into v13/dev Dec 9, 2024
@elit0451 elit0451 deleted the v13/feature/delivery-api-user-info-endpoint branch December 9, 2024 08:57
@bjarnef
Copy link
Contributor

bjarnef commented Dec 12, 2024

@kjac any scheduled release date for v13.6.0? Perhaps an early Christmas present? 😉😍🎁🎄🎅

@bjarnef
Copy link
Contributor

bjarnef commented Feb 4, 2025

The implementation is build to be extendable, so custom claims can be added to these claims - and the core claims can be removed, too.

@kjac do you have an example of this?

I have something like this:

public class CustomCurrentMemberClaimsProvider : CurrentMemberClaimsProvider
{
    private readonly IMemberManager _memberManager;

    public CustomCurrentMemberClaimsProvider(IMemberManager memberManager) : base(memberManager)
    {
        _memberManager = memberManager;
    }

    protected override async Task<Dictionary<string, object>> GetClaimsForMemberIdentityAsync(MemberIdentityUser memberIdentityUser)
    {
        var claims = await base.GetClaimsForMemberIdentityAsync(memberIdentityUser);

        var member = _memberManager.AsPublishedMember(memberIdentityUser) as Member;

        //claims[OpenIddictConstants.Claims.PhoneNumber] = await _memberManager.GetPhoneNumberAsync(memberIdentityUser);

        if (member is not null)
        {
            claims["committees"] = member.Committees?.Select(x => x.Name).ToList() ?? [];
        }

        return claims;
    }
}

but unsure how it should override/replace the default.

I tried something like this in a composer:

public void Compose(IUmbracoBuilder builder)
{
    var existingMemberClaimsProviderRegistration = builder.Services.FirstOrDefault(service => service.ServiceType == typeof(CurrentMemberClaimsProvider));
    
    if (existingMemberClaimsProviderRegistration != null)
        builder.Services.Remove(existingMemberClaimsProviderRegistration);

    builder.Services.AddTransient<ICurrentMemberClaimsProvider, CustomCurrentMemberClaimsProvider>();
}

I also added some documentation of the userinfo endpoint here. Feel free to add any adjustments :)
umbraco/UmbracoDocs#6849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants