Exemplo n.º 1
0
        /// <summary>
        /// Final step to the OAuth authorization process.
        /// Make a request to the TokenRequestEndpoint to finally get the token credentials.
        /// (if provided, the temporaryCredentials argument is used over the temporary credentials of this instance)
        /// </summary>
        public TokenCredentials RequestTokenCredentials(string verifier, TemporaryCredentials temporaryCredentials = null)
        {
            if (temporaryCredentials == null)
            {
                temporaryCredentials = this.TemporaryCredentials;
            }
            if (temporaryCredentials == null)
            {
                throw new ArgumentNullException("temporaryCredentials", "The temporaryCredentials argument is null, and this.TemporaryCredentials is also null!");
            }

            HttpWebRequest request         = Util.CreateRequest(Util.HttpMethod.POST, this.TokenRequestEndpoint);
            var            oAuthParameters = OAuthHelper.GetQueryParameters(this.ClientCredentials.Identifier, this.SignatureMethod,
                                                                            new QueryParameter(OAuthParameter.Token, temporaryCredentials.Identifier),
                                                                            new QueryParameter(OAuthParameter.Verifier, verifier));

            OAuthHelper.MakeRequestAuthenticated(request, oAuthParameters, this.ClientCredentials.SharedSecret, temporaryCredentials.SharedSecret);

            string responseString;

            Util.TryGetResponse(request, out responseString);

            var parsed       = OAuthHelper.ParseParameters(responseString);
            var identifier   = parsed.Single(x => x.Name == OAuthParameter.Token.ToStringValue()).Value;
            var sharedSecret = parsed.Single(x => x.Name == OAuthParameter.TokenSecret.ToStringValue()).Value;

            return(new TokenCredentials(identifier, sharedSecret));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return an uri formed by the combination of the ResourceOwnerAuthorizationEndpoint and the temporary credentials.
        /// call RequestTemporaryCredentials() beforehand to obtain the temporary credentials.
        /// (if provided, the temporaryCredentials argument is used over the temporary credentials of this instance)
        /// </summary>
        /// <returns></returns>
        public string GetAuthorizationUri(TemporaryCredentials temporaryCredentials = null)
        {
            if (temporaryCredentials == null)
            {
                temporaryCredentials = this.TemporaryCredentials;
            }
            if (temporaryCredentials == null)
            {
                throw new ArgumentNullException("temporaryCredentials", "The temporaryCredentials argument is null, and this.TemporaryCredentials is also null!");
            }

            return(string.Format("{0}?{1}={2}",
                                 this.ResourceOwnerAuthorizationEndpoint, OAuthParameter.Token.ToStringValue(), temporaryCredentials.Identifier));
        }