private async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
        {
            AzureAdSettings azureADSettings = GetAdSettings(context);


            context.HandleCodeRedemption();

        }
        internal static Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
        {
            Helpers.ThrowIfConditionFailed(() => context.TokenEndpointRequest.Code == "AAABAAAAvPM1KaPlrEqdFSBzjqfTGGBtrTYVn589oKw4lLgJ6Svz0AhPVOJr0J2-Uu_KffGlqIbYlRAyxmt-vZ7VlSVdrWvOkNhK9OaAMaSD7LDoPbBTVMEkB0MdAgBTV34l2el-s8ZI02_9PvgQaORZs7n8eGaGbcoKAoxiDn2OcKuJVplXYgrGUwU4VpRaqe6RaNzuseM7qBFbLIv4Wps8CndE6W8ccmuu6EvGC6-H4uF9EZL7gU4nEcTcvkE4Qyt8do6VhTVfM1ygRNQgmV1BCig5t_5xfhL6-xWQdy15Uzn_Df8VSsyDXe8s9cxyKlqc_AIyLFy_NEiMQFUqjZWKd_rR3A8ugug15SEEGuo1kF3jMc7dVMdE6OF9UBd-Ax5ILWT7V4clnRQb6-CXB538DlolREfE-PowXYruFBA-ARD6rwAVtuVfCSbS0Zr4ZqfNjt6x8yQdK-OkdQRZ1thiZcZlm1lyb2EquGZ8Deh2iWBoY1uNcyjzhG-L43EivxtHAp6Y8cErhbo41iacgqOycgyJWxiB5J0HHkxD0nQ2RVVuY8Ybc9sdgyfKkkK2wZ3idGaRCdZN8Q9VBhWRXPDMqHWG8t3aZRtvJ_Xd3WhjNPJC0GpepUGNNQtXiEoIECC363o1z6PZC5-E7U3l9xK06BZkcfTOnggUiSWNCrxUKS44dNqaozdYlO5E028UgAEhJ4eDtcP3PZty-0j4j5Mw0F2FmyAA",
                "context.TokenEndpointRequest.Code is invalid.");
            eventsFired.Add(nameof(AuthorizationCodeReceived));

            // Verify all events are fired.
            if (eventsFired.Contains(nameof(RedirectToIdentityProvider)) &&
                eventsFired.Contains(nameof(MessageReceived)) &&
                eventsFired.Contains(nameof(TokenValidated)) &&
                eventsFired.Contains(nameof(AuthorizationCodeReceived)))
            {
                ((ClaimsIdentity)context.Ticket.Principal.Identity).AddClaim(new Claim("ManageStore", "Allowed"));
            }

            return Task.FromResult(0);
        }
        private async Task <AuthorizationCodeReceivedContext> RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage authorizationResponse, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt)
        {
            Logger.AuthorizationCodeReceived();

            var tokenEndpointRequest = new OpenIdConnectMessage()
            {
                ClientId     = Options.ClientId,
                ClientSecret = Options.ClientSecret,
                Code         = authorizationResponse.Code,
                GrantType    = OpenIdConnectGrantTypes.AuthorizationCode,
                RedirectUri  = properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey]
            };

            var authorizationCodeReceivedContext = new AuthorizationCodeReceivedContext(Context, Options)
            {
                ProtocolMessage      = authorizationResponse,
                Properties           = properties,
                TokenEndpointRequest = tokenEndpointRequest,
                Ticket           = ticket,
                JwtSecurityToken = jwt,
                Backchannel      = Backchannel,
            };

            await Options.Events.AuthorizationCodeReceived(authorizationCodeReceivedContext);

            if (authorizationCodeReceivedContext.HandledResponse)
            {
                Logger.AuthorizationCodeReceivedContextHandledResponse();
            }
            else if (authorizationCodeReceivedContext.Skipped)
            {
                Logger.AuthorizationCodeReceivedContextSkipped();
            }

            return(authorizationCodeReceivedContext);
        }
Beispiel #4
0
 /// <summary>
 /// Invoked if an authorization code is present in the protocol message.
 /// </summary>
 public virtual Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context) => OnAuthorizationCodeReceived(context);
        public override async Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context)
        {
            var principal = context.Ticket.Principal;

            //
            var request = context.HttpContext.Request;
            var currentUri = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path);
            var properties = context.Properties;

            //

            var surveysTokenService = context.HttpContext.RequestServices.GetService<ISurveysTokenService>();
            try
            {
                await surveysTokenService.RequestTokenAsync(
                    principal,
                    context.ProtocolMessage.Code,
                    currentUri,
                    _adOptions.WebApiResourceId)
                    .ConfigureAwait(false);
            }
            catch
            {
                // If an exception is thrown within this event, the user is never set on the OWIN middleware,
                // so there is no need to sign out.  However, the access token could have been put into the
                // cache so we need to clean it up.
                await surveysTokenService.ClearCacheAsync(principal)
                    .ConfigureAwait(false);
                throw;
            }

        }
Beispiel #6
0
 public virtual Task AuthorizationCodeReceived(AuthorizationCodeReceivedContext context) => OnAuthorizationCodeReceived(context);