Exemplo n.º 1
0
        protected virtual async Task <AuthenticationTicket> CreateTicketAsync(
            ClaimsIdentity identity,
            AuthenticationProperties properties,
            AccessToken token)
        {
            log.LogDebug("CreateTicketAsync called tokens.ScreenName was " + token.ScreenName);

            var notification = new TwitterAuthenticatedContext(Context, token.UserId, token.ScreenName, token.Token, token.TokenSecret)
            {
                Principal  = new ClaimsPrincipal(identity),
                Properties = properties
            };

            await Options.Notifications.Authenticated(notification);

            if (notification.Principal?.Identity == null)
            {
                return(null);
            }

            ISiteSettings site = siteResolver.Resolve();

            if (site != null)
            {
                Claim siteGuidClaim = new Claim("SiteGuid", site.SiteGuid.ToString());
                if (!identity.HasClaim(siteGuidClaim.Type, siteGuidClaim.Value))
                {
                    identity.AddClaim(siteGuidClaim);
                }
            }

            //return new AuthenticationTicket(notification.Principal, notification.Properties, Options.AuthenticationScheme);
            return(new AuthenticationTicket(notification.Principal, notification.Properties, AuthenticationScheme.External));
        }
Exemplo n.º 2
0
        public override Task Authenticated(TwitterAuthenticatedContext context)
        {
            context.Identity.AddClaim(new Claim(ExternalAccessToken, context.AccessToken));
            context.Identity.AddClaim(new Claim(ScreenName, context.ScreenName));
            context.Identity.AddClaim(new Claim(UserId, context.UserId));
            context.Identity.AddClaim(new Claim(AccessTokenSecret, context.AccessTokenSecret));

            return(Task.FromResult <object>(null));
        }
 public override Task Authenticated(TwitterAuthenticatedContext context)
 {
     context.Identity.AddClaims(
         new List<Claim>
         {
         new Claim(AccessToken, context.AccessToken),
         new Claim(AccessTokenSecret, context.AccessTokenSecret)
         });
     return base.Authenticated(context);
 }
Exemplo n.º 4
0
        internal static async Task OnAuthenticated(TwitterAuthenticatedContext context)
        {
            if (context.Identity != null)
            {
                Helpers.ThrowIfConditionFailed(() => context.UserId == "valid_user_id", "UserId is not valid");
                Helpers.ThrowIfConditionFailed(() => context.ScreenName == "valid_screen_name", "ScreenName is not valid");
                Helpers.ThrowIfConditionFailed(() => context.AccessToken == "valid_oauth_token", "AccessToken is not valid");
                Helpers.ThrowIfConditionFailed(() => context.AccessTokenSecret == "valid_oauth_token_secret", "AccessTokenSecret is not valid");
                context.Identity.AddClaim(new Claim("ManageStore", "false"));
            }

            await Task.FromResult(0);
        }
Exemplo n.º 5
0
 //
 public override Task Authenticated(TwitterAuthenticatedContext context)
 {
     try
     {
         addClaim(context.Identity, "urn:tokens:twitter:accesstoken", context.AccessToken);
         addClaim(context.Identity, "urn:tokens:twitter:accesssecret", context.AccessTokenSecret);
         //
         //addClaim(context.Identity, "urn:tokens:twitter:familyname", getValue(context.User, "last_name"));
         //addClaim(context.Identity, "urn:tokens:twitter:givenname", getValue(context.User, "first_name"));
         //addClaim(context.Identity, "urn:tokens:twitter:avatarurl", "");
         //addClaim(context.Identity, "urn:tokens:twitter:company", getValue(context.User, "company"));
         //
         //addClaim(context.Identity, "urn:tokens:twitter:userid", context.UserId);
         //addClaim(context.Identity, "urn:tokens:twitter:screenname", context.ScreenName);
     }
     catch (Exception ex) { Logger.Error(ex, LogCategory.Claims, "There was an issue reading the information from the Facebook Authentication context."); }
     //
     return(base.Authenticated(context));
 }
Exemplo n.º 6
0
 public override Task Authenticated(TwitterAuthenticatedContext context)
 {
     context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken));
     context.Identity.AddClaim(new Claim("UserId", context.UserId));
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 7
0
 public Task ReturnEndpoint(TwitterAuthenticatedContext context)
 {
     return(Task.FromResult <object>(null));
 }
Exemplo n.º 8
0
 public void ApplyRedirect(TwitterAuthenticatedContext context)
 {
     context.Response.Redirect(context.Properties.RedirectUri);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Invoked whenever Twitter succesfully 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(TwitterAuthenticatedContext context)
 {
     return(OnAuthenticated(context));
 }
Exemplo n.º 10
0
 public Task Authenticated(TwitterAuthenticatedContext context)
 {
     context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken));
     context.Identity.AddClaim(new Claim("AccessTokenSecret", context.AccessTokenSecret));
     return(Task.FromResult <object>(null));
 }
        protected override async Task <AuthenticationTicket> AuthenticateCoreAsync()
        {
            AuthenticationProperties properties = null;

            try
            {
                IReadableStringCollection query = Request.Query;
                string protectedRequestToken    = Request.Cookies[StateCookie];

                RequestToken requestToken = Options.StateDataFormat.Unprotect(protectedRequestToken);

                if (requestToken == null)
                {
                    _logger.WriteWarning("Invalid state");
                    return(null);
                }

                properties = requestToken.Properties;

                string returnedToken = query.Get("oauth_token");
                if (string.IsNullOrWhiteSpace(returnedToken))
                {
                    _logger.WriteWarning("Missing oauth_token");
                    return(new AuthenticationTicket(null, properties));
                }

                if (returnedToken != requestToken.Token)
                {
                    _logger.WriteWarning("Unmatched token");
                    return(new AuthenticationTicket(null, properties));
                }

                string oauthVerifier = query.Get("oauth_verifier");
                if (string.IsNullOrWhiteSpace(oauthVerifier))
                {
                    _logger.WriteWarning("Missing or blank oauth_verifier");
                    return(new AuthenticationTicket(null, properties));
                }

                AccessToken accessToken = await ObtainAccessTokenAsync(Options.ConsumerKey, Options.ConsumerSecret, requestToken, oauthVerifier);

                var context = new TwitterAuthenticatedContext(Context, accessToken.UserId, accessToken.ScreenName, accessToken.Token, accessToken.TokenSecret);

                context.Identity = new ClaimsIdentity(
                    new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType),
                    new Claim(ClaimTypes.Name, accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType),
                    new Claim("urn:twitter:userid", accessToken.UserId, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType),
                    new Claim("urn:twitter:screenname", accessToken.ScreenName, "http://www.w3.org/2001/XMLSchema#string", Options.AuthenticationType)
                },
                    Options.AuthenticationType,
                    ClaimsIdentity.DefaultNameClaimType,
                    ClaimsIdentity.DefaultRoleClaimType);
                context.Properties = requestToken.Properties;

                Response.Cookies.Delete(StateCookie);

                await Options.Provider.Authenticated(context);

                return(new AuthenticationTicket(context.Identity, context.Properties));
            }
            catch (Exception ex)
            {
                _logger.WriteError("Authentication failed", ex);
                return(new AuthenticationTicket(null, properties));
            }
        }