Skip to content

Commit

Permalink
fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Feb 7, 2016
1 parent cfabb74 commit f560380
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IdentityServer3.Core.Services;
using IdentityServer3.Core;
using IdentityServer3.Core.Services;
using IdentityServer3.Core.Validation;
using System;
using System.Collections.Generic;
Expand All @@ -19,28 +20,32 @@ public ActAsGrantValidator(TokenValidator validator)

Task<CustomGrantValidationResult> ICustomGrantValidator.ValidateAsync(ValidatedTokenRequest request)
{
CustomGrantValidationResult grantResult = null;

var param = request.Raw.Get("token");
if (string.IsNullOrWhiteSpace(param))
{
return Task.FromResult<CustomGrantValidationResult>(
new CustomGrantValidationResult("Token parameter not set."));
grantResult = new CustomGrantValidationResult(Constants.TokenErrors.InvalidRequest);
}

var result = _validator.ValidateAccessTokenAsync(param).Result;
if (result.IsError)
{
return Task.FromResult<CustomGrantValidationResult>(
new CustomGrantValidationResult(result.Error));
grantResult = new CustomGrantValidationResult(result.Error);
}

var subjectClaim = result.Claims.FirstOrDefault(x => x.Type == "sub");
if(subjectClaim == null)
{
return Task.FromResult<CustomGrantValidationResult>(
new CustomGrantValidationResult("No subject claim for the token."));
grantResult = new CustomGrantValidationResult(Constants.TokenErrors.InvalidRequest);
}

if (grantResult == null)
{
grantResult = new CustomGrantValidationResult(subjectClaim.Value, "access_token");
}

return Task.FromResult(new CustomGrantValidationResult(subjectClaim.Value, "act-as"));
return Task.FromResult(grantResult);
}

public string GrantType
Expand Down

0 comments on commit f560380

Please sign in to comment.