當前位置: 首頁>>代碼示例>>C#>>正文


C# Infrastructure.AuthenticationTokenReceiveContext類代碼示例

本文整理匯總了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext的典型用法代碼示例。如果您正苦於以下問題:C# AuthenticationTokenReceiveContext類的具體用法?C# AuthenticationTokenReceiveContext怎麽用?C# AuthenticationTokenReceiveContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AuthenticationTokenReceiveContext類屬於Microsoft.Owin.Security.Infrastructure命名空間,在下文中一共展示了AuthenticationTokenReceiveContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。