예제 #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));
 }
예제 #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);
        }
예제 #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);
        }
예제 #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");
 }
예제 #5
0
 public static OAuth2Message CreateFromEncodedResponse(System.IO.StreamReader reader)
 {
     return(OAuth2MessageFactory.CreateFromEncodedResponse(reader.ReadToEnd()));
 }