Beispiel #1
0
        /// <summary>
        ///  The core authentication logic.
        /// </summary>
        /// <returns>The ticket data provided by the authentication logic.</returns>
        protected async override System.Threading.Tasks.Task <AuthenticationTicket> AuthenticateCoreAsync()
        {
            AuthenticationProperties properties = UnpackStateParameter(Request.Query);

            if (properties != null)
            {
                var logonUserIdentity = Options.Provider.GetLogonUserIdentity(Context);

                if (logonUserIdentity.AuthenticationType != Options.CookieOptions.AuthenticationType && logonUserIdentity.IsAuthenticated)
                {
                    AddCookieBackIfExists();

                    ClaimsIdentity claimsIdentity = new ClaimsIdentity(logonUserIdentity.Claims, Options.SignInAsAuthenticationType);

                    //name identifier
                    // Microsoft.Owin.Security.AuthenticationManagerExtensions: ExternalLoginInfo GetExternalLoginInfo(AuthenticateResult result)
                    claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, logonUserIdentity.User.Value, null, Options.AuthenticationType));

                    // Import custom claims.
                    List <Claim> customClaims = Options.Provider.ImportClaims(logonUserIdentity);
                    claimsIdentity.AddClaims(customClaims
                                             .Where(c => c.Type != ClaimTypes.NameIdentifier)
                                             .Select(c => new Claim(c.Type, c.Value, c.ValueType, Options.AuthenticationType)));

                    var ticket = new AuthenticationTicket(claimsIdentity, properties);

                    var context = new MixedAuthAuthenticatedContext(
                        Context,
                        claimsIdentity,
                        properties,
                        Options.AccessTokenFormat.Protect(ticket));

                    await Options.Provider.Authenticated(context);

                    return(ticket);
                }
            }
            return(new AuthenticationTicket(null, properties));
        }
Beispiel #2
0
 /// <summary>
 /// Invoked whenever MixedAuth successfully authenticates a user
 /// </summary>
 /// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task Authenticated(MixedAuthAuthenticatedContext context)
 {
     return(OnAuthenticated(context));
 }