Browse Source

refactor mode to a property

Signed-off-by: Gehongyan <gehongyan1996@126.com>
pull/2403/head
Gehongyan 2 months ago
parent
commit
41d4c0b05f
  1. 16
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs
  2. 6
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

16
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationHandlers.cs

@ -635,7 +635,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
= OpenIddictClientHandlerDescriptor.CreateBuilder<ProcessAuthenticationContext>()
.AddFilter<RequireTokenRequest>()
.UseSingletonHandler<OverrideScope>()
.SetOrder(AttachTokenRequestParameters.Descriptor.Order + 250)
.SetOrder(AttachTokenRequestParameters.Descriptor.Order - 500)
.SetType(OpenIddictClientHandlerType.BuiltIn)
.Build();
@ -647,14 +647,13 @@ public static partial class OpenIddictClientWebIntegrationHandlers
throw new ArgumentNullException(nameof(context));
}
Debug.Assert(context.TokenRequest is not null, SR.GetResourceString(SR.ID4008));
// osu! requires that the scope must be "public" for client credentials
// grant, as other scopes have no meaningful effect.
if (context.GrantType is GrantTypes.ClientCredentials &&
context.Registration.ProviderType is ProviderTypes.Osu)
{
context.TokenRequest.Scope = "public";
context.Scopes.Add("public");
// TODO: how does user code add custom scopes here?
}
return ValueTask.CompletedTask;
@ -963,7 +962,7 @@ public static partial class OpenIddictClientWebIntegrationHandlers
// Note: these providers don't have a static userinfo endpoint attached to their configuration
// so OpenIddict doesn't, by default, send a userinfo request. Since a dynamic endpoint is later
// computed and attached to the context, the default value MUST be overridden to send a request.
ProviderTypes.Dailymotion or ProviderTypes.HubSpot or
ProviderTypes.Dailymotion or ProviderTypes.HubSpot or ProviderTypes.Osu or
ProviderTypes.SuperOffice or ProviderTypes.Zoho
when context.GrantType is GrantTypes.AuthorizationCode or GrantTypes.DeviceCode or
GrantTypes.Implicit or GrantTypes.Password or
@ -1099,6 +1098,13 @@ public static partial class OpenIddictClientWebIntegrationHandlers
left : new Uri("https://api.hubapi.com/oauth/v1/access-tokens", UriKind.Absolute),
right: new Uri(token, UriKind.Relative)),
// osu! supports specifying a game mode when querying the userinfo endpoint.
ProviderTypes.Osu
=> !context.Properties.TryGetValue(Osu.Properties.GameMode, out string? gameMode) ||
string.IsNullOrEmpty(gameMode) ?
new Uri("https://osu.ppy.sh/api/v2/me", UriKind.Absolute) :
new Uri($"https://osu.ppy.sh/api/v2/me/{gameMode}", UriKind.Absolute),
// SuperOffice doesn't expose a static OpenID Connect userinfo endpoint but offers an API whose
// absolute URI needs to be computed based on a special claim returned in the identity token.
ProviderTypes.SuperOffice when

6
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationProviders.xml

@ -1759,8 +1759,7 @@
Documentation="https://osu.ppy.sh/docs/index.html#authentication">
<Environment Issuer="https://osu.ppy.sh/">
<Configuration AuthorizationEndpoint="https://osu.ppy.sh/oauth/authorize"
TokenEndpoint="https://osu.ppy.sh/oauth/token"
UserInfoEndpoint="{(string.IsNullOrEmpty(settings.GameMode) ? 'https://osu.ppy.sh/api/v2/me' : $'https://osu.ppy.sh/api/v2/me/{settings.GameMode}')}">
TokenEndpoint="https://osu.ppy.sh/oauth/token">
<GrantType Value="authorization_code" />
<GrantType Value="client_credentials" />
<GrantType Value="refresh_token" />
@ -1773,8 +1772,7 @@
<Constant Class="GameMode" Value="fruits" Name="Catch" />
<Constant Class="GameMode" Value="mania" Name="Mania" />
<Setting PropertyName="GameMode" ParameterName="mode" Type="String" Required="false"
Description="The game mode to retrieve statistics for (e.g., 'osu', 'taiko', 'fruits', 'mania'). User default mode will be used if not specified" />
<Property Name="GameMode" DictionaryKey=".game_mode" />
</Provider>
<!--

Loading…
Cancel
Save