Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add teaching_record scope to Authorize access & require it #1272

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ public async Task<IActionResult> Authorize()
var request = HttpContext.GetOpenIddictServerRequest() ??
throw new InvalidOperationException("The OpenID Connect request cannot be retrieved.");

if (!request.HasScope(CustomScopes.TeachingRecord))
{
return Forbid(
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
properties: new AuthenticationProperties(new Dictionary<string, string?>()
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidRequest,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] =
$"Requests must include the {CustomScopes.TeachingRecord} scope."
}));
}

var clientId = request.ClientId!;
var client = await dbContext.ApplicationUsers.SingleAsync(u => u.ClientId == clientId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TeachingRecordSystem.AuthorizeAccess;

public static class CustomScopes
{
public const string TeachingRecord = "teaching_record";
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
.SetTokenEndpointUris("oauth2/token")
.SetUserinfoEndpointUris("oauth2/userinfo");

// TODO - add teaching record scopes
options.RegisterScopes(Scopes.Email, Scopes.Profile);
options.RegisterScopes(Scopes.Email, Scopes.Profile, CustomScopes.TeachingRecord);

options.AllowAuthorizationCodeFlow();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static WebApplicationBuilder AddTestApp(this WebApplicationBuilder builde
options.Scope.Add("openid");
options.Scope.Add("email");
options.Scope.Add("profile");
options.Scope.Add(CustomScopes.TeachingRecord);
});
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public void EnsureConfiguredForOneLogin()
Permissions.GrantTypes.AuthorizationCode,
Permissions.ResponseTypes.Code,
Permissions.Scopes.Email,
Permissions.Scopes.Profile),
Permissions.Scopes.Profile,
$"{Permissions.Prefixes.Scope}teaching_record"),
RedirectUris = CreateJsonArray(RedirectUris!.ToArray()),
PostLogoutRedirectUris = CreateJsonArray(PostLogoutRedirectUris!.ToArray()),
Requirements = CreateJsonArray(Requirements.Features.ProofKeyForCodeExchange)
Expand Down
Loading