|
1 | 1 | using Microsoft.IdentityModel.Claims;
|
| 2 | +using System; |
| 3 | +using System.Linq; |
2 | 4 | using System.ServiceModel.Security.Tokens;
|
3 | 5 | using System.Xml;
|
4 | 6 |
|
@@ -412,6 +414,7 @@ private ClaimsIdentityCollection ValidateTokenCore(System.IdentityModel.Tokens.S
|
412 | 414 | ClaimsIdentity claimsIdentity = new ClaimsIdentity("Federation");
|
413 | 415 | if (!isActorToken && jsonWebSecurityToken.ActorToken != null)
|
414 | 416 | {
|
| 417 | + ValidateActorTokenForAppOnly(jsonWebSecurityToken.ActorToken); |
415 | 418 | ClaimsIdentityCollection claimsIdentityCollection2 = this.ValidateActorToken(jsonWebSecurityToken.ActorToken);
|
416 | 419 | if (claimsIdentityCollection2.Count > 1)
|
417 | 420 | {
|
@@ -440,6 +443,24 @@ private ClaimsIdentityCollection ValidateTokenCore(System.IdentityModel.Tokens.S
|
440 | 443 | return claimsIdentityCollection;
|
441 | 444 | }
|
442 | 445 |
|
| 446 | + /// <summary> |
| 447 | + ///Validates that the actor token is an app token by checking for the lack of user claims |
| 448 | + /// </summary> |
| 449 | + /// <param name="actorToken"></param> |
| 450 | + private static void ValidateActorTokenForAppOnly(JsonWebSecurityToken actorToken) |
| 451 | + { |
| 452 | + if (actorToken != null) |
| 453 | + { |
| 454 | + if (actorToken.Claims.FirstOrDefault<JsonWebTokenClaim>(x => x.ClaimType.Equals("scp")) != null |
| 455 | + || actorToken.Claims.FirstOrDefault<JsonWebTokenClaim>(x => x.ClaimType.Equals("upn")) != null |
| 456 | + || actorToken.Claims.FirstOrDefault<JsonWebTokenClaim>(x => x.ClaimType.Equals("unique_name")) != null |
| 457 | + || actorToken.Claims.FirstOrDefault<JsonWebTokenClaim>(x => x.ClaimType.Equals("altsecid")) != null) |
| 458 | + { |
| 459 | + throw new UnauthorizedAccessException("Invalid actor token."); |
| 460 | + } |
| 461 | + } |
| 462 | + } |
| 463 | + |
443 | 464 | public override ClaimsIdentityCollection ValidateToken(System.IdentityModel.Tokens.SecurityToken token)
|
444 | 465 | {
|
445 | 466 | return this.ValidateTokenCore(token, false);
|
|
0 commit comments