Exemplo n.º 1
0
 public static OAuth2AccessTokenRequest CreateAccessTokenRequestWithAssertion(System.IdentityModel.Tokens.SecurityToken token, string resource)
 {
     Utility.VerifyNonNullArgument("token", token);
     Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection securityTokenHandlerCollection = Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
     securityTokenHandlerCollection.Add(new JsonWebSecurityTokenHandler());
     return(OAuth2MessageFactory.CreateAccessTokenRequestWithAssertion(token, securityTokenHandlerCollection, resource));
 }
Exemplo n.º 2
0
        private static OAuth2AccessTokenRequest CreateAccessTokenRequestWithAssertion(System.IdentityModel.Tokens.GenericXmlSecurityToken token, string resource)
        {
            Utility.VerifyNonNullArgument("token", token);
            OAuth2AccessTokenRequest    oAuth2AccessTokenRequest    = new OAuth2AccessTokenRequest();
            JsonWebSecurityTokenHandler jsonWebSecurityTokenHandler = new JsonWebSecurityTokenHandler();

            System.Xml.XmlReader reader = new System.Xml.XmlNodeReader(token.TokenXml);
            string text;
            string jsonTokenString = jsonWebSecurityTokenHandler.GetJsonTokenString(reader, out text);

            oAuth2AccessTokenRequest.GrantType = OAuth2MessageFactory.GetTokenType(token);
            oAuth2AccessTokenRequest.Assertion = jsonTokenString;
            oAuth2AccessTokenRequest.Resource  = resource;
            return(oAuth2AccessTokenRequest);
        }
Exemplo n.º 3
0
        public OAuth2Message Issue(string securityTokenServiceUrl, OAuth2AccessTokenRequest oauth2Request)
        {
            OAuth2WebRequest oAuth2WebRequest = new OAuth2WebRequest(securityTokenServiceUrl, oauth2Request);
            OAuth2Message    result;

            try
            {
                System.Net.WebResponse response = oAuth2WebRequest.GetResponse();
                result = OAuth2MessageFactory.CreateFromEncodedResponse(new System.IO.StreamReader(response.GetResponseStream()));
            }
            catch (System.Exception innerException)
            {
                throw new RequestFailedException("Token request failed.", innerException);
            }
            return(result);
        }
Exemplo n.º 4
0
 public static OAuth2AccessTokenRequest CreateAccessTokenRequestWithAssertion(System.IdentityModel.Tokens.SecurityToken token, Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection securityTokenHandlers, string resource)
 {
     Utility.VerifyNonNullArgument("token", token);
     if (token is JsonWebSecurityToken)
     {
         return(OAuth2MessageFactory.CreateAccessTokenRequestWithAssertion((JsonWebSecurityToken)token, securityTokenHandlers, resource));
     }
     if (token is System.IdentityModel.Tokens.GenericXmlSecurityToken)
     {
         return(OAuth2MessageFactory.CreateAccessTokenRequestWithAssertion((System.IdentityModel.Tokens.GenericXmlSecurityToken)token, resource));
     }
     if (token is System.IdentityModel.Tokens.SamlSecurityToken || token is Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityToken)
     {
         return(OAuth2MessageFactory.CreateAccessTokenRequestWithAssertionForSamlSecurityTokens(token, securityTokenHandlers, resource));
     }
     throw new System.ArgumentException("Unsupported SecurityToken");
 }
Exemplo n.º 5
0
 public static OAuth2Message CreateFromEncodedResponse(System.IO.StreamReader reader)
 {
     return(OAuth2MessageFactory.CreateFromEncodedResponse(reader.ReadToEnd()));
 }