当前位置: 首页>>代码示例>>C#>>正文


C# AuthenticationTokenReceiveContext.SetTicket方法代码示例

本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext.SetTicket方法的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenReceiveContext.SetTicket方法的具体用法?C# AuthenticationTokenReceiveContext.SetTicket怎么用?C# AuthenticationTokenReceiveContext.SetTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext的用法示例。


在下文中一共展示了AuthenticationTokenReceiveContext.SetTicket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {            
            //PIN lockout not yet implemented. Might integrated with account lockout or its own thing
            //Uncomment this to accept a post parameter called "pin"
            //IFormCollection form = await context.Request.ReadFormAsync();
            //string submittedPin = form["PIN"];
            
            if(!String.IsNullOrEmpty(context.Token)){
                Guid refreshToken = Guid.Parse(context.Token);
                if(refreshToken != null){
                    ApplicationDbContext dbContext = context.OwinContext.Get<ApplicationDbContext>();

                    OAuthSession oauthSession = dbContext.OAuthSessions.SingleOrDefault(oas => oas.RefreshToken == refreshToken);
                    OAuthClient oauthClient = context.OwinContext.Get<OAuthClient>(NicksApplicationOAuthProvider.OwinClientKey);

                    if (oauthSession != null && oauthClient != null && oauthSession.ClientId == oauthClient.Id && oauthClient.OrganizationId == oauthSession.OrganizationId && oauthSession.IsRefreshTokenValid(refreshToken, Startup.RefreshTokenTimeSpan))
                    {
                        ApplicationUserManager userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
                        ApplicationUser user = await userManager.FindByIdAsync(oauthSession.UserId);
                        //Uncomment this and the closing brace to verify the PIN hash referenced above
                        //if (userManager.PasswordHasher.VerifyHashedPassword(user.PINHash,submittedPin) == PasswordVerificationResult.Success)
                        //{
                            context.OwinContext.Set<ApplicationUser>(NicksApplicationOAuthProvider.OwinUserKey, user);
                            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType);
                            IDictionary<string, string> properties = new Dictionary<string, string>{ { "userName", user.UserName } };
                            AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties(properties));
                            ticket.Properties.IssuedUtc = DateTimeOffset.UtcNow;
                            ticket.Properties.ExpiresUtc = DateTimeOffset.UtcNow.Add(Startup.OAuthOptions.AccessTokenExpireTimeSpan);
                            context.SetTicket(ticket);
                        //}
                    }
                }
            }
        }
开发者ID:akhilnaruto,项目名称:nicksoauthserver,代码行数:34,代码来源:NicksRefreshTokenProvider.cs

示例2: ReceiveAsync

        public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var url = string.Format(_tokenValidationEndpoint, context.Token);
            
            var response = await _client.GetAsync(url);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            var jsonString = await response.Content.ReadAsStringAsync();
            var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);

            var claims = new List<Claim>();

            foreach (var item in dictionary)
            {
                var values = item.Value as IEnumerable<object>;

                if (values == null)
                {
                    claims.Add(new Claim(item.Key, item.Value.ToString()));
                }
                else
                {
                    foreach (var value in values)
                    {
                        claims.Add(new Claim(item.Key, value.ToString()));
                    }
                }
            }

            context.SetTicket(new AuthenticationTicket(new ClaimsIdentity(claims, _authenticationType), new AuthenticationProperties()));
        }
开发者ID:eugv86,项目名称:Thinktecture.IdentityServer.v3.Samples,代码行数:34,代码来源:ReferenceTokenProvider.cs

示例3: Receive

 public void Receive(AuthenticationTokenReceiveContext context)
 {
     var oAuthIdentity = new ClaimsIdentity();
     oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, "jeremy"));
     var ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties());
     context.SetTicket(ticket);
 }
开发者ID:appcoreopc,项目名称:OAuthZ,代码行数:7,代码来源:SimpleRefreshTokenProvider.cs

示例4: ReceiveAsync

 public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     TicketResult result = await RemoveAsync(context);
     if (result.Deleted)
     {
         context.SetTicket(result.Ticket);
     }
 }
开发者ID:Xamarui,项目名称:Owin.Security.RedisTokenProviders,代码行数:8,代码来源:RedisRefreshTokenProvider.cs

示例5: Receive

 public void Receive(AuthenticationTokenReceiveContext context)
 {
     TicketResult result = Remove(context);
     if (result.Deleted)
     {
         context.SetTicket(result.Ticket);
     }
 }
开发者ID:Xamarui,项目名称:Owin.Security.RedisTokenProviders,代码行数:8,代码来源:RedisRefreshTokenProvider.cs

示例6: ReceiveAsync

 public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     AuthenticationTicket ticket;
     if (_refreshTokens.TryRemove(context.Token, out ticket))
     {
         context.SetTicket(ticket);
     }
 }
开发者ID:alxwest,项目名称:OpenFiddle,代码行数:8,代码来源:RefreshTokenProvider.cs

示例7: Receive

 public void Receive(AuthenticationTokenReceiveContext context)
 {
     //TODO: before generating a new ticket, validate the ticket has not expired, and has never
     //been used to generate a new ticket
     var token = new CustomTokenFormat().Unprotect(context.Token.Replace(" ", "+"));
     var ticket = AuthTicketBuilder.BuildTicket(token);
     context.SetTicket(ticket);
 }
开发者ID:szahn,项目名称:AngularWebApiOAuthDemo,代码行数:8,代码来源:OAuthRefreshTokenProvider.cs

示例8: Receive

 public void Receive(AuthenticationTokenReceiveContext context)
 {
     AuthenticationTicket ticket;
     if (RefreshTokens.TryRemove(context.Token, out ticket))
     {
         context.SetTicket(ticket);
     }
 }
开发者ID:rainymaple,项目名称:PCG.GOAL,代码行数:8,代码来源:GoalRefreshTokenProvider.cs

示例9: ReceiveAsync

 //<summary>
 //验证Token
 //</summary>
 //<param name="context">上下文</param>
 //<returns></returns>
 public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     var request = new OAuthRequestTokenContext(context.OwinContext, context.Token);
     var ticket = new AuthenticationTicket(new ClaimsIdentity(), new AuthenticationProperties()
     {
         IssuedUtc = DateTime.UtcNow.AddYears(-1),
         ExpiresUtc = DateTime.UtcNow.AddYears(-1)
     });
     if (request == null || request.Token.IsNullOrEmpty())
     {
         context.SetTicket(ticket);
     }
     //验证Token是否过期
     var vaild = true;//await _clientAuthorizationService.VaildOAuthClientSecretAsync();
     if (vaild)
     {
         context.SetTicket(ticket);
     }
 }
开发者ID:WhitePoplar022,项目名称:App.WebAPI,代码行数:24,代码来源:AccessTokenAuthorizationServerProvider.cs

示例10: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            AuthenticationTicket ticket;
            string header = context.OwinContext.Request.Headers["Authorization"];

            if (_refreshTokens.TryRemove(context.Token, out ticket))
            {
                context.SetTicket(ticket);
            }
        }
开发者ID:andyhoyle,项目名称:Crucial.Framework,代码行数:10,代码来源:RefreshTokenProvider.cs

示例11: ReceiveAsync

        public override Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var tokenValidator = new TokenValidator();

            ClaimsPrincipal principal = tokenValidator.Validate(context.Token, _options);

            context.SetTicket(new AuthenticationTicket((ClaimsIdentity)principal.Identity,
                new AuthenticationProperties()));

            return base.ReceiveAsync(context);
        }
开发者ID:jayway,项目名称:JayLabs.Owin.OAuthAuthorization,代码行数:11,代码来源:JwtBearerTokenProvider.cs

示例12: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type" });

            AuthenticationTicket ticket;
            if (_refreshTokens.TryRemove(context.Token, out ticket))
            {
                context.SetTicket(ticket);
            }
            //return Task.FromResult<object>(null);
        }
开发者ID:jango2015,项目名称:WebApiBearerToken,代码行数:12,代码来源:SimpleRefreshTokenProvider.cs

示例13: ReceiveAsync

 public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     //var hashedTokenId = CryptoAes.GetHash(context.Token);
     using (var authenticationTokenService = _dependencyResolver.GetService<IAuthenticationTokenFactory>())
     {
         var ticket = await authenticationTokenService.IssueAuthenticationTicketAsync(context.Token);
         if (ticket != null)
         {
             context.SetTicket(ticket);
         }
     }
 }
开发者ID:mdarlea,项目名称:Demo-Restaurant,代码行数:12,代码来源:OAuthRefreshTokenProvider.cs

示例14: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            Guid token;
            if (Guid.TryParse(context.Token, out token))
            {
                AuthenticationTicket ticket;

                if (_refreshTokens.TryRemove(ComputeHash(token), out ticket))
                {
                    context.SetTicket(ticket);
                }
            }
        }
开发者ID:daniel-williams,项目名称:skyberry2016,代码行数:13,代码来源:RefreshTokenProvider.cs

示例15: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            string clientId = context.OwinContext.Get<string>("as:client_id");
            string ticket = refreshTokenService.GetAuthenticationTicket(new Guid(context.Token), clientId);
            if (!string.IsNullOrEmpty(ticket) && !string.IsNullOrWhiteSpace(ticket))
            {
                context.SetTicket(serializer.Deserialize(System.Text.Encoding.Default.GetBytes(ticket)));

                var command = new ReduceRefreshTokenTTL()
                {
                    ClientId = clientId,
                    RefreshToken = Guid.Parse(context.Token),
                    AuthenticationTicket = ticket,
                    TTL = ttlChange
                };

                this.commandBus.Send(command);
            }
        }
开发者ID:hoangvv1409,项目名称:codebase,代码行数:19,代码来源:RefreshTokenProvider.cs


注:本文中的Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext.SetTicket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。