Beispiel #1
0
        public async Task <IActionResult> Callback()
        {
            // read external identity from the temporary cookie
            var externalResult = await HttpContext.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);

            var result = (await _externalService.ProcessExternalAuthentication(externalResult))
                         .ValueOr(e => throw new Exception(e));

            var localSignInProps = new AuthenticationProperties {
                IsPersistent = false
            };

            result.ExternalIdToken.MatchSome(extIdToken =>
            {
                // if the external provider issued an id_token, we'll keep it for signout
                localSignInProps.StoreTokens(new[] { new AuthenticationToken {
                                                         Name = "id_token", Value = extIdToken
                                                     } });
            });

            await HttpContext.SignInAsync(result.IsUser, localSignInProps);

            // delete temporary cookie used during external authentication
            await HttpContext.SignOutAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);

            return(result.UseNativeClientRedirect
                ? this.LoadingPage("Redirect", result.ReturnUrl)
                : Redirect(result.ReturnUrl));
        }