// 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; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNet.Authentication.OpenIdConnect; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.IdentityModel.Protocols; using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { /// /// Allows for custom processing of ApplyResponseChallenge, ApplyResponseGrant and AuthenticateCore /// public class OpenIdConnectAuthenticationHandlerForTestingAuthenticate : OpenIdConnectAuthenticationHandler { public OpenIdConnectAuthenticationHandlerForTestingAuthenticate() : base(null) { } protected override async Task HandleUnauthorizedAsync(ChallengeContext context) { return await base.HandleUnauthorizedAsync(context); } protected override Task HandleSignInAsync(SignInContext context) { return Task.FromResult(0); } protected override Task HandleSignOutAsync(SignOutContext context) { return Task.FromResult(0); } protected override async Task RedeemAuthorizationCodeAsync(string authorizationCode, string redirectUri) { var jsonResponse = new JObject(); jsonResponse.Add(OpenIdConnectParameterNames.IdToken, "test token"); return new OpenIdConnectTokenEndpointResponse(jsonResponse); } protected override async Task GetUserInformationAsync(AuthenticationProperties properties, OpenIdConnectMessage message, AuthenticationTicket ticket) { var claimsIdentity = (ClaimsIdentity)ticket.Principal.Identity; if (claimsIdentity == null) { claimsIdentity = new ClaimsIdentity(); } claimsIdentity.AddClaim(new Claim("test claim", "test value")); return new AuthenticationTicket(new ClaimsPrincipal(claimsIdentity), ticket.Properties, ticket.AuthenticationScheme); } //public override bool ShouldHandleScheme(string authenticationScheme) //{ // return true; //} } }