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


C# Tokens.SecurityToken类代码示例

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


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

示例1: GetIssuerName

        /// <summary>
        /// Overrides the base class. Validates the given issuer token. For a incoming SAML token
        /// the issuer token is the Certificate that signed the SAML token.
        /// </summary>
        /// <param name="securityToken">Issuer token to be validated.</param>
        /// <returns>Friendly name representing the Issuer.</returns>
        public override string GetIssuerName(SecurityToken securityToken)
        {
            CustomTextTraceSource ts = new CustomTextTraceSource("IdentityProviderSts.IdentityProviderIssuerNameRegistry.GetIssuerName",
                "MyTraceSource", SourceLevels.Information);

            X509SecurityToken x509Token = securityToken as X509SecurityToken;
            if (x509Token != null)
            {
                // Warning: This sample does a simple compare of the Issuer Certificate
                // to a subject name. This is not appropriate for production use. 
                // Check your validation policy and authenticate issuers based off the policy.
                
                string commonName = x509Token.Certificate.GetNameInfo(X509NameType.SimpleName, false);

                ts.TraceInformation("Certificate CN: " + commonName);

                //if (String.Equals(x509Token.Certificate.SubjectName.Name, "O=CA for Ref GFIPM, [email protected], C=US, S=GA, CN=Reference GFIPM Federation") ||
                //    String.Equals(x509Token.Certificate.SubjectName.Name, "O=CISA, C=US, S=GA, CN=cisaidp.swbs.gtri.gatech.edu"))
                //if (String.Equals(x509Token.Certificate.SubjectName.Name, "O=CISA, C=US, S=GA, CN=cisaidp.swbs.gtri.gatech.edu"))
                if (String.Equals(commonName.ToUpper(), "HA50IDP"))
                {
                    return x509Token.Certificate.SubjectName.Name;
                }
            }

            ts.TraceInformation("Untrusted issuer");

            throw new SecurityTokenException("Untrusted issuer.");
        }
开发者ID:gtkrug,项目名称:gfipm-ws-ms.net,代码行数:35,代码来源:IdentityProviderIssuerNameRegistry.cs

示例2: TryResolveTokenCore

 protected override bool TryResolveTokenCore(SecurityKeyIdentifier keyIdentifier, out SecurityToken token)
 {
     bool flag = false;
     token = null;
     flag = this.tokenResolver.TryResolveToken(keyIdentifier, false, false, out token);
     if (!flag && (this.outOfBandTokenResolvers != null))
     {
         for (int i = 0; i < this.outOfBandTokenResolvers.Count; i++)
         {
             flag = this.outOfBandTokenResolvers[i].TryResolveToken(keyIdentifier, out token);
             if (flag)
             {
                 break;
             }
         }
     }
     if (!flag)
     {
         for (int j = 0; j < keyIdentifier.Count; j++)
         {
             if (this.TryResolveTokenFromIntrinsicKeyClause(keyIdentifier[j], out token))
             {
                 return true;
             }
         }
     }
     return flag;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:28,代码来源:AggregateTokenResolver.cs

示例3: ValidateToken

        public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters, out SecurityToken validatedToken)
        {

            //eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmlxdWVfbmFtZSI6Ikphc29uIExlZSIsInN1YiI6Ikphc29uIExlZSIsInJvbGUiOlsiTWFuYWdlciIsIlN1cGVydmlzb3IiXSwiaXNzIjoiaHR0cDovL2p3dGF1dGh6c3J2LmF6dXJld2Vic2l0ZXMubmV0IiwiYXVkIjoiUm9ja2V0IiwiZXhwIjoxNDQxOTgwMjE5LCJuYmYiOjE0NDE5NzY2MTl9.yegylhGkz5uasu5E--aEbCAHfi5aE9Z17_pZAE63Bog

            validatedToken = null;


            var key = "IxrAjDoa2FqElO7IhrSrUJELhUckePEPVpaePlS_Xaw";
            
            try
            {
                var raw = JsonWebToken.Decode(securityToken, key);

                var payLoad = JsonConvert.DeserializeObject<List<KeyValuePair<string, string>>>(raw);

                var claims = new List<Claim>();

                foreach (var row in payLoad)
                {
                    var claim = new Claim(row.Key, row.Value);
                    claims.Add(claim);
                }

                var claimsIdentity = new ClaimsIdentity(claims, "jwt");

                return new ClaimsPrincipal(claimsIdentity);
            }
            catch (Exception ex)
            {
                return null;

            }
            
        }
开发者ID:JasonSoft,项目名称:single-sign-on,代码行数:35,代码来源:CustomJwtSecurityTokenHandler.cs

示例4: GetIssuerName

        /// <summary>
        /// Overrides the base class. Validates the given issuer token. For a incoming SAML token
        /// the issuer token is the Certificate that signed the SAML token.
        /// </summary>
        /// <param name="securityToken">Issuer token to be validated.</param>
        /// <returns>Friendly name representing the Issuer.</returns>
        public override string GetIssuerName(SecurityToken securityToken)
        {
            CustomTextTraceSource ts = new CustomTextTraceSource("IdpAds.IdpAdsIssuerNameRegistry.GetIssuerName",
                "MyTraceSource", SourceLevels.Information);

            //TraceSource ts = new TraceSource("System.ServiceModel");

            X509SecurityToken x509Token = securityToken as X509SecurityToken;
            if (x509Token != null)
            {
                // Warning: This sample does a simple compare of the Issuer Certificate
                // to a subject name. This is not appropriate for production use. 
                // Check your validation policy and authenticate issuers based off the policy.

                string commonName = x509Token.Certificate.GetNameInfo(X509NameType.SimpleName, false);

                ts.TraceInformation("Certificate CN: " + commonName);

                // TODO: Why this is different in the 
                if (CertificateUtil.ValidateCertificate(StoreName.TrustedPeople, StoreLocation.LocalMachine, x509Token.Certificate))
                {
                    ts.TraceInformation("Certificate VALID");

                    return x509Token.Certificate.SubjectName.Name;
                }
            }

            ts.TraceInformation("Untrusted issuer");

            throw new SecurityTokenException("Untrusted issuer.");
        }
开发者ID:gtkrug,项目名称:gfipm-ws-ms.net,代码行数:37,代码来源:AdsIssuerNameRegistry.cs

示例5: GetIssuedToken

 public static SecurityToken GetIssuedToken(string STSUrl, string audience, string signingCertificateNameClient, SecurityToken bootstrapToken)
 {
     
     var certificate2Client = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateNameClient);
     var certificate2Service = CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SigningCertificateNameSTS);
     return TokenClient.GetIssuedToken(new Uri(audience), certificate2Client, certificate2Service, new Uri(STSUrl), bootstrapToken);
 }
开发者ID:amagdenko,项目名称:oiosaml.java,代码行数:7,代码来源:TokenUtil.cs

示例6: ValidateToken

        //public override bool CanReadToken(XmlReader reader)
        //{
        //    bool canRead = false;
        //    if (reader != null)
        //    {
        //        if (reader.IsStartElement(BinarySecurityToken)
        //            && (reader.GetAttribute(ValueType) == SimpleWebTokenConstants.ValueTypeUri))
        //        {
        //            canRead = true;
        //        }
        //    }
        //    return canRead;
        //}
        public override ReadOnlyCollection<ClaimsIdentity> ValidateToken(SecurityToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var saml2Token = token as Saml2SecurityToken;
            if (saml2Token == null)
            {
                throw new ArgumentException("The token provided must be of type Saml2SecurityToken.");
            }

            if (DateTime.Compare(saml2Token.ValidTo.Add(Configuration.MaxClockSkew), DateTime.UtcNow) <= 0)
            {
                throw new SecurityTokenExpiredException(
                    "The incoming token has expired. Get a new access token from the Authorization Server.");
            }

            //this.ValidateSignature(simpleWebToken);

            //ValidateAudience(simpleWebToken.Audience);

            ClaimsIdentity claimsIdentity = CreateClaims(saml2Token);

            //if (this.Configuration.SaveBootstrapContext)
            //{
            //    claimsIdentity.BootstrapContext = new BootstrapContext(saml2Token.SerializedToken);
            //}

            var claimCollection = new List<ClaimsIdentity>(new[] { claimsIdentity });
            return claimCollection.AsReadOnly();
        }
开发者ID:JeffMaslo,项目名称:Token-Maker,代码行数:46,代码来源:CustomSaml2TokenHandler.cs

示例7: GetIssuerName

        /// <summary>
        /// Overrides the base class. Validates the given issuer token. For a incoming SAML token
        /// the issuer token is the Certificate that signed the SAML token.
        /// </summary>
        /// <param name="securityToken">Issuer token to be validated.</param>
        /// <returns>Friendly name representing the Issuer.</returns>
        public override string GetIssuerName(SecurityToken securityToken)
        {
            Common.CustomTextTraceSource ts = new Common.CustomTextTraceSource("CommercialVehicleCollisionWebservice.WspTrustedIssuerNameRegistry.GetIssuerName",
                "MyTraceSource", SourceLevels.Information);

            
            X509SecurityToken x509Token = securityToken as X509SecurityToken;
            if (x509Token != null)
            {
                // Warning: This sample does a simple compare of the Issuer Certificate
                // to a subject name. This is not appropriate for production use. 
                // Check your validation policy and authenticate issuers based off the policy.

                ts.TraceInformation("IssuerName: " + x509Token.Certificate.SubjectName.Name);

                string commonName = x509Token.Certificate.GetNameInfo(X509NameType.SimpleName, false);
                ts.TraceInformation("CommonName: " + commonName);

                if (CertificateUtil.ValidateCertificate(StoreName.TrustedPeople, StoreLocation.LocalMachine, x509Token.Certificate))
                {
                    ts.TraceInformation("Certificate is valid");

                    return x509Token.Certificate.SubjectName.Name;
                }
                else
                {
                    ts.TraceInformation("Certificate is NOT VALID");
                }
            }

            throw new SecurityTokenException("Untrusted issuer.");            
        }
开发者ID:gtkrug,项目名称:gfipm-ws-ms.net,代码行数:38,代码来源:WspTrustedIssuerNameRegistry.cs

示例8: TryIssueToken

        public bool TryIssueToken(EndpointReference appliesTo, ClaimsPrincipal principal, string tokenType,
            out SecurityToken token)
        {
            token = null;

            var rst = new RequestSecurityToken
            {
                RequestType = RequestTypes.Issue,
                AppliesTo = appliesTo,
                KeyType = KeyTypes.Bearer,
                TokenType = tokenType
            };

            try
            {
                var rstr = _sts.Issue(principal, rst);
                token = rstr.RequestedSecurityToken.SecurityToken;
                return true;
            }
            catch (Exception e)
            {
                Tracing.Error("Failed to issue token. An exception occurred. " + e);
                return false;
            }
        }
开发者ID:azhuang88,项目名称:IdentityServer,代码行数:25,代码来源:STS.cs

示例9: SamlToJwtAsync

        public async Task<string> SamlToJwtAsync(SecurityToken token, string realm)
        {
            var samlToken = token as SamlSecurityToken;
            if (samlToken == null) throw new ArgumentException("token not an instance of a SamlSecurityToken");

            return await SamlToJwtAsync(samlToken.ToTokenXmlString(), realm);
        }
开发者ID:EduOrtega,项目名称:Thinktecture.IdentityServer.v2,代码行数:7,代码来源:AdfsIntegrationProxy.cs

示例10: RequestSecurityTokenResponse

 public RequestSecurityTokenResponse(string context, string tokenType, int keySize, EndpointAddress appliesTo, SecurityToken requestedSecurityToken, SecurityToken requestedProofToken, bool computeKey )
     : base(context, tokenType, keySize, appliesTo)
 {
     this.m_requestedSecurityToken = requestedSecurityToken;
     this.m_requestedProofToken = requestedProofToken;
     this.m_computeKey = computeKey;
 }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:7,代码来源:RequestSecurityTokenResponse.cs

示例11: ResolveSecurityToken

        void ResolveSecurityToken()
        {
            if ( _securityToken == null )
            {
                lock ( _lock )
                {
                    if ( _securityToken == null )
                    {
                        ClientCredentialsSecurityTokenManager.KerberosSecurityTokenProviderWrapper kerbTokenProvider = _tokenProvider 
                                                        as ClientCredentialsSecurityTokenManager.KerberosSecurityTokenProviderWrapper;
                        if (kerbTokenProvider != null)
                        {
                            _securityToken = kerbTokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime(), _channelBinding);
                        }
                        else
                        {
                            _securityToken = _tokenProvider.GetToken((new TimeoutHelper(_timeout)).RemainingTime());
                        }
                    }
                }
            }

            if ( _securityToken == null )
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SecurityTokenException( SR.GetString( SR.SecurityTokenNotResolved, _tokenProvider.GetType().ToString() ) ) );
            }

            return;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:29,代码来源:ProviderBackedSecurityToken.cs

示例12: DerivedKeySecurityToken

 internal DerivedKeySecurityToken(int generation, int offset, int length, string label, byte[] nonce, SecurityToken tokenToDerive, SecurityKeyIdentifierClause tokenToDeriveIdentifier, string derivationAlgorithm, string id)
 {
     this.length = -1;
     this.offset = -1;
     this.generation = -1;
     this.Initialize(id, generation, offset, length, label, nonce, tokenToDerive, tokenToDeriveIdentifier, derivationAlgorithm, false);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:DerivedKeySecurityToken.cs

示例13: JwtAuthenticationOwinMiddleware

 public JwtAuthenticationOwinMiddleware(AppFunc next, IEnumerable<string> AllowedAudiences, string Issuer, SecurityToken SigningToken)
 {
     this.next = next;
     this.AllowedAudiences = AllowedAudiences;
     this.Issuer = Issuer;
     this.SigningToken = SigningToken;
 }
开发者ID:cangosta,项目名称:JwtAuthForWebAPI,代码行数:7,代码来源:JwtAuthenticationOwinMiddleware.cs

示例14: EnsureWrappedToken

 private void EnsureWrappedToken(SecurityToken token, Message message)
 {
     if (!(token is WrappedKeySecurityToken))
     {
         throw TraceUtility.ThrowHelperError(new MessageSecurityException(System.ServiceModel.SR.GetString("IncomingSigningTokenMustBeAnEncryptedKey")), message);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:SymmetricSecurityProtocol.cs

示例15: CreateKeyIdentifierClause

 internal protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause(SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
 {
     if (token is GenericXmlSecurityToken)
         return base.CreateGenericXmlTokenKeyIdentifierClause(token, referenceStyle);
     else
         return this.CreateKeyIdentifierClause<SecurityContextKeyIdentifierClause, LocalIdKeyIdentifierClause>(token, referenceStyle);
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:SspiSecurityTokenParameters.cs


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