Skip to content

Commit

Permalink
Revert: Added flexible subdomain support for UserInfo endpoint (#750)
Browse files Browse the repository at this point in the history
* Revert "Update src/AspNet.Security.OAuth.SuperOffice/SuperOfficeAuthenticationHandler.cs"

This reverts commit 8388be4.

* Revert "Decontruct result from getting tenant id and webapi url."

This reverts commit b2f8527.

* Revert "Added flexible subdomain support for UserInfo endpoint. Updated docs link."

This reverts commit 2ec4b74.
  • Loading branch information
martincostello authored Dec 15, 2022
1 parent 8388be4 commit e775895
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
| Stack Exchange | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.StackExchange?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.StackExchange/ "Download AspNet.Security.OAuth.StackExchange from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.StackExchange?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.StackExchange "Download AspNet.Security.OAuth.StackExchange from MyGet.org") | [Documentation](https://api.stackexchange.com/docs/authentication "Stack Exchange developer documentation") |
| Strava | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Strava?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Strava/ "Download AspNet.Security.OAuth.Strava from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Strava?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Strava "Download AspNet.Security.OAuth.Strava from MyGet.org") | [Documentation](https://developers.strava.com/docs/authentication/ "Strava developer documentation") |
| Streamlabs | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Streamlabs?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Streamlabs/ "Download AspNet.Security.OAuth.Streamlabs from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Streamlabs?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Streamlabs "Download AspNet.Security.OAuth.Streamlabs from MyGet.org") | [Documentation](https://dev.streamlabs.com/reference#authorize "Streamlabs developer documentation") |
| SuperOffice | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.SuperOffice?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.SuperOffice/ "Download AspNet.Security.OAuth.SuperOffice from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.SuperOffice?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.SuperOffice "Download AspNet.Security.OAuth.SuperOffice from MyGet.org") | [Documentation](https://docs.superoffice.com/authentication/online/index.html "SuperOffice developer documentation") |
| SuperOffice | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.SuperOffice?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.SuperOffice/ "Download AspNet.Security.OAuth.SuperOffice from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.SuperOffice?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.SuperOffice "Download AspNet.Security.OAuth.SuperOffice from MyGet.org") | [Documentation](https://community.superoffice.com/en/developer/create-apps/concepts/authentication/ "SuperOffice developer documentation") |
| Trakt | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Trakt?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Trakt/ "Download AspNet.Security.OAuth.Trakt from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Trakt?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Trakt "Download AspNet.Security.OAuth.Trakt from MyGet.org") | [Documentation](https://trakt.docs.apiary.io/ "Trakt developer documentation") |
| Trovo | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Trovo?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Trovo/ "Download AspNet.Security.OAuth.Trovo from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Trovo?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Trovo "Download AspNet.Security.OAuth.Trovo from MyGet.org") | [Documentation](https://developer.trovo.live/docs/APIs.html "Trovo developer documentation") |
| Twitch | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Twitch?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Twitch/ "Download AspNet.Security.OAuth.Twitch from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Twitch?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Twitch "Download AspNet.Security.OAuth.Twitch from MyGet.org") | [Documentation](https://dev.twitch.tv/docs/authentication/ "Twitch developer documentation") |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal static class FormatStrings
/// </summary>
/// <remarks>The final user information URL contains the protocol, host and tenant.</remarks>
/// <example>https://sod.superoffice.com/Cust12345/api/v1/user/currentPrincipal</example>
public const string UserInfoEndpoint = "{0}v1/user/currentPrincipal";
public const string UserInfoEndpoint = "/{0}/api/v1/user/currentPrincipal";
}

public static class PrincipalNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,15 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{
(string tenantId, string webApiUrl) = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity);
var contextId = await ProcessIdTokenAndGetContactIdentifierAsync(tokens, properties, identity);

if (string.IsNullOrEmpty(tenantId))
if (string.IsNullOrEmpty(contextId))
{
throw new InvalidOperationException("An error occurred trying to obtain the context identifier from the current user's identity claims.");
}

if (string.IsNullOrEmpty(webApiUrl))
{
throw new InvalidOperationException("An error occurred trying to obtain the WebApi from the current user's identity claims.");
}

// UserInfo endpoint must support multiple subdomains, i.e. sod, sod1, online, online1, online2, ...
// - subdomain only becomes known from id token
// Example WebApi Url https://sod.superoffice.com/Cust12345/api/
var userInfoEndpoint = string.Format(CultureInfo.InvariantCulture, SuperOfficeAuthenticationConstants.FormatStrings.UserInfoEndpoint, webApiUrl);
// Add contextId to the Options.UserInformationEndpoint (https://sod.superoffice.com/{0}/api/v1/user/currentPrincipal).
var userInfoEndpoint = string.Format(CultureInfo.InvariantCulture, Options.UserInformationEndpoint, contextId);

// Get the SuperOffice user principal.
using var request = new HttpRequestMessage(HttpMethod.Get, userInfoEndpoint);
Expand All @@ -76,7 +69,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
}

private async Task<(string TenantId, string WebApiUrl)> ProcessIdTokenAndGetContactIdentifierAsync(
private async Task<string> ProcessIdTokenAndGetContactIdentifierAsync(
[NotNull] OAuthTokenResponse tokens,
[NotNull] AuthenticationProperties properties,
[NotNull] ClaimsIdentity identity)
Expand All @@ -92,7 +85,6 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
var tokenValidationResult = await ValidateAsync(idToken, Options.TokenValidationParameters.Clone());

var contextIdentifier = string.Empty;
var webApiUrl = string.Empty;

foreach (var claim in tokenValidationResult.ClaimsIdentity.Claims)
{
Expand All @@ -101,11 +93,6 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
contextIdentifier = claim.Value;
}

if (claim.Type == SuperOfficeAuthenticationConstants.ClaimNames.WebApiUrl)
{
webApiUrl = claim.Value;
}

if (claim.Type == SuperOfficeAuthenticationConstants.ClaimNames.SubjectIdentifier)
{
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, claim.Value));
Expand All @@ -122,7 +109,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
}
}

return (contextIdentifier, webApiUrl);
return contextIdentifier;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ private void UpdateEndpoints()
FormatStrings.ClaimsIssuer,
env);

// UserInformationEndpoint will include context identifier after authentication in SuperOfficeAuthenticationHandler.CreateTicketAsync
UserInformationEndpoint = string.Concat(ClaimsIssuer, FormatStrings.UserInfoEndpoint);

MetadataAddress = string.Format(CultureInfo.InvariantCulture,
FormatStrings.MetadataEndpoint,
env);
Expand Down

0 comments on commit e775895

Please sign in to comment.