• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Infrastructure.AuthenticationTokenReceiveContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



AuthenticationTokenReceiveContext类属于Microsoft.Owin.Security.Infrastructure命名空间,在下文中一共展示了AuthenticationTokenReceiveContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: ReceiveAsync

 public Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     return Task.Run(() =>
     {
         Receive(context);
     });
 }
开发者ID:szahn,项目名称:AngularWebApiOAuthDemo,代码行数:7,代码来源:OAuthRefreshTokenProvider.cs


示例3: ReceiveAsync

    public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
    {
      try
      {
        var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";
        context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

        var hashedTokenId = Helper.GetHash(context.Token);
        using (IRepository rep = new ApplicationRepository())
        {
          var refreshToken = await rep.RefreshTokens.FindAsync(hashedTokenId);

          if (refreshToken != null)
          {
            //Get protectedTicket from refreshToken class
            context.DeserializeTicket(refreshToken.ProtectedTicket);
            var result = await rep.RefreshTokens.RemoveAsync(hashedTokenId);
          }
        }

      }
      catch (Exception e)
      {
        
        throw e;
      }
    }
开发者ID:Fanuer,项目名称:fitnessApp,代码行数:27,代码来源:CustomRefreshTokenProvider.cs


示例4: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            try
            {

                var hashedTokenId = HashHelper.GetHash(context.Token);


                using (AuthRepository authService = new AuthRepository())
                {
                    var refreshToken = authService.FindRefreshToken(hashedTokenId);                   

                    if (refreshToken != null)
                    {
                        //Get protectedTicket from refreshToken class
                        context.DeserializeTicket(refreshToken.ProtectedTicket);
                        //remove token from db 
                        var result = authService.RemoveRefreshToken(hashedTokenId);
                    }
                }

            }
            catch (Exception ex)
            {
                Logger.Error("Error receiving token: " + ex.InnerException);
            }
        }
开发者ID:inmWill,项目名称:api.core,代码行数:27,代码来源:SimpleRefreshTokenProvider.cs


示例5: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");

            if (context.OwinContext.Response.Headers.Keys.Contains("Access-Control-Allow-Origin"))
            {
                context.OwinContext.Response.Headers["Access-Control-Allow-Origin"] = allowedOrigin;
            }
            else
            {
                context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {allowedOrigin});
            }

            var hashedTokenId = TokenHelper.GetHash(context.Token);

            using (var _repo = new AuthRepository())
            {
                var refreshToken = await _repo.FindRefreshToken(hashedTokenId);

                if (refreshToken != null)
                {
                    //Get protectedTicket from refreshToken class
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    var result = await _repo.RemoveRefreshToken(hashedTokenId);
                }
            }
        }
开发者ID:chivandikwa,项目名称:Angular-Starter,代码行数:27,代码来源:SimpleRefreshTokenProvider.cs


示例6: 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


示例7: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            // define o cabecalho da resposta do contexto do Owin com a permição de origem
            var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            // pega o Id do token pelo na requisição
            var hashedTokenId = HashHelper.GetHash(context.Token);

            // Identifica o Browser
            var userAgent = HttpContext.Current.Request.UserAgent;
            var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
            var factory = new BrowserCapabilitiesFactory();
            factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
            var browser = userBrowser.Browser;

            var refreshTokenDomain = DependecyConfig.Container.GetInstance<IRefreshTokenDomain>();
            // busca o token na base de dados pelo id
            var refreshToken = await refreshTokenDomain.ReadAsync(hashedTokenId, browser);

            // se o token for encontrado
            if (refreshToken != null)
            {
                // pega os dados do ticket para deserializar e gerar um novo ticket com 
                // as informações mapeadas do usuário que utiliza este token
                var ticketSerializer = new TicketSerializer();
                var ticket = ticketSerializer.Deserialize(refreshToken.ProtectedTicket);

                context.SetTicket(ticket);

                // remove o token da base de dados pois em nossa lógica, permitimos apenas 
                // um RefreshToken por usuário e aplicação cliente
                await refreshTokenDomain.DeleteAsync(hashedTokenId, browser);
            }
        }
开发者ID:TaigoSantos,项目名称:Visual-Studio,代码行数:35,代码来源:SimpleRefreshTokenProvider.cs


示例8: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {

            using (var ctx = new ApplicationDbContext())
            {
                // Get the hash of our token
                var hash = Encryption.Hash(context.Token);

                // Find the refresh token by its hash
                var rt = (from r in ctx.RefreshTokens
                          where r.Id == hash
                          select r).SingleOrDefault();

                if (rt != null)
                {
                    // Get ticket from stored data
                    context.DeserializeTicket(rt.Ticket);
                    // Delete the token from the DB
                    ctx.RefreshTokens.Remove(rt);

                    // Save changes
                    await ctx.SaveChangesAsync();

                }
                
            }

        }
开发者ID:KryptPad,项目名称:KryptPadWebsite,代码行数:28,代码来源:RefreshTokenProvider.cs


示例9: 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


示例10: Receive

 /// <summary>
 /// 
 /// </summary>
 /// <param name="context"></param>
 public override void Receive(AuthenticationTokenReceiveContext context)
 {
     string token;
     if (_refreshTokens.TryRemove(context.Token, out token))
     {
         context.DeserializeTicket(token);
     }
 }
开发者ID:xianrui,项目名称:osharp,代码行数:12,代码来源:OsharpRefreshTokenProvider.cs


示例11: 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


示例12: 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


示例13: Receive

 public override void Receive(AuthenticationTokenReceiveContext context)
 {
     string value;
     if (_codes.TryRemove(context.Token, out value))
     {
         context.DeserializeTicket(value);
     }
 }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:8,代码来源:OsharpAuthorizationCodeProvider.cs


示例14: ReceiveAuthenticationCode

 private void ReceiveAuthenticationCode(AuthenticationTokenReceiveContext context)
 {
     string value;
     if (_authCodes.TryRemove(context.Token, out value))
     {
         context.DeserializeTicket(value);
     }
 }
开发者ID:austinejei,项目名称:sidekick,代码行数:8,代码来源:SideKickOAuthImplementation.cs


示例15: 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


示例16: 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


示例17: 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


示例18: ReceiveAsync

        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            await Task.Run(() =>
            {
                context.DeserializeTicket(context.Token);
            });

            
        }
开发者ID:akapolonn,项目名称:AngularJSAuthentication,代码行数:10,代码来源:MyRefreshTokenProvider.cs


示例19: 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


示例20: ReceiveAsync

 /// <summary>
 /// 移除RefreshToken,在客户端使用RefreshToken请求新的AccessToken的时候自动调用
 /// </summary>
 /// <param name="context"></param>
 public async override Task ReceiveAsync(AuthenticationTokenReceiveContext context)
 {
     RefreshTokenInfo token = await _clientRefreshTokenStore.GetTokenInfo(context.Token);
     if (token == null)
     {
         return;
     }
     context.DeserializeTicket(token.ProtectedTicket);
     await _clientRefreshTokenStore.Remove(context.Token);
 }
开发者ID:i66soft,项目名称:osharp,代码行数:14,代码来源:OsharpRefreshTokenProvider.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap