41 lines
1.7 KiB
C#
41 lines
1.7 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNet.Authentication.OpenIdConnect;
|
|
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|
{
|
|
/// <summary>
|
|
/// Allows for custom processing of ApplyResponseChallenge, ApplyResponseGrant and AuthenticateCore
|
|
/// </summary>
|
|
public class OpenIdConnectHandlerForTestingAuthenticate : OpenIdConnectHandler
|
|
{
|
|
public OpenIdConnectHandlerForTestingAuthenticate() : base(null, null)
|
|
{
|
|
}
|
|
|
|
protected override Task<OpenIdConnectMessage> RedeemAuthorizationCodeAsync(string authorizationCode, string redirectUri)
|
|
{
|
|
var jsonResponse = new JObject();
|
|
jsonResponse.Add(OpenIdConnectParameterNames.IdToken, "test token");
|
|
return Task.FromResult(new OpenIdConnectMessage(jsonResponse));
|
|
}
|
|
|
|
protected override Task<AuthenticationTicket> GetUserInformationAsync(OpenIdConnectMessage message, JwtSecurityToken jwt, AuthenticationTicket ticket)
|
|
{
|
|
var claimsIdentity = (ClaimsIdentity)ticket.Principal.Identity;
|
|
if (claimsIdentity == null)
|
|
{
|
|
claimsIdentity = new ClaimsIdentity();
|
|
}
|
|
claimsIdentity.AddClaim(new Claim("test claim", "test value"));
|
|
return Task.FromResult(new AuthenticationTicket(new ClaimsPrincipal(claimsIdentity), ticket.Properties, ticket.AuthenticationScheme));
|
|
}
|
|
}
|
|
}
|