mirror of
https://github.com/tomasvarg/OwinWebApiTest.git
synced 2026-03-01 08:28:49 +00:00
Added custom props support to the token-granted response
This commit is contained in:
parent
099d1c2aa8
commit
aee4bd408e
@ -39,8 +39,8 @@ namespace OwinWebApiTest.Providers
|
|||||||
dynamic args = await context.Request.ReadFormAsync();
|
dynamic args = await context.Request.ReadFormAsync();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(args["ticket"]) || string.IsNullOrEmpty(args["service"])) {
|
if (string.IsNullOrEmpty(args["ticket"]) || string.IsNullOrEmpty(args["service"])) {
|
||||||
context.SetError("invalid_grant", "No CAS ticket or service URL sent.");
|
|
||||||
context.Rejected();
|
context.Rejected();
|
||||||
|
context.SetError("invalid_grant", "No CAS ticket or service URL sent.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,13 +59,17 @@ namespace OwinWebApiTest.Providers
|
|||||||
|
|
||||||
//var acda = new AccessControlDA();
|
//var acda = new AccessControlDA();
|
||||||
//var ac = acda.GetAccessControl(res.success.user);
|
//var ac = acda.GetAccessControl(res.success.user);
|
||||||
var ac = new { userId = args["username"], saveAllowed = true, saveAllUnits = true };
|
var ac = new { userId = res.success.user, canRead = true, canSave = true };
|
||||||
|
|
||||||
|
if (ac == null) {
|
||||||
|
context.Rejected();
|
||||||
|
context.SetError("invalid_grant", $"User '{res.success.user}' not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType);
|
ClaimsIdentity identity = new ClaimsIdentity(context.Options.AuthenticationType);
|
||||||
identity.AddClaim(new Claim(ClaimTypes.Name, res.success.user));
|
identity.AddClaim(new Claim(ClaimTypes.Name, res.success.user));
|
||||||
identity.AddClaim(new Claim(ClaimTypes.Role, "User"));
|
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
|
||||||
//identity.AddClaim(new Claim("user_name", context.UserName));
|
|
||||||
//identity.AddClaim(new Claim("sub", context.UserName));
|
|
||||||
|
|
||||||
// Identity info will be encoded into an Access ticket as a result of this call:
|
// Identity info will be encoded into an Access ticket as a result of this call:
|
||||||
//context.Validated(identity);
|
//context.Validated(identity);
|
||||||
@ -79,6 +83,17 @@ namespace OwinWebApiTest.Providers
|
|||||||
context.Validated(ticket);
|
context.Validated(ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// needed to get the custom props as a part of the token-granted response
|
||||||
|
public override Task TokenEndpoint(OAuthTokenEndpointContext context)
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<string, string> property in context.Properties.Dictionary)
|
||||||
|
{
|
||||||
|
context.AdditionalResponseParameters.Add(property.Key, property.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult<object>(null);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<CasServiceValidationResponse> ValidateCasTicket(string ticket, string service)
|
private async Task<CasServiceValidationResponse> ValidateCasTicket(string ticket, string service)
|
||||||
{
|
{
|
||||||
var requestUri = WebUtilities.AddQueryString(casValidationUrl, new Dictionary<string, string>() {
|
var requestUri = WebUtilities.AddQueryString(casValidationUrl, new Dictionary<string, string>() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user