Пример #1
0
        /// <summary>
        /// Constructs a request state key from a service and
        /// an end user id. The service realm is taken to be the OAuthService.Realm
        /// property or else the OAuthService.AuthorizationUri if the realm is null.
        /// The consumer key is loaded from the service
        /// </summary>
        /// <param name="service">Service</param>
        /// <param name="endUserId">End user identifier</param>
        public RequestStateKey(OAuthService service, string endUserId)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            string serviceRealm = null;

            if (!string.IsNullOrEmpty(service.Realm))
            {
                serviceRealm = service.Realm;
            }
            else if (service.AuthorizationUrl != null)
            {
                serviceRealm = service.AuthorizationUrl.AbsoluteUri;
            }
            else
            {
                throw new ArgumentException("Service does not have realm or authorization URI", "service");
            }

            if (service.Consumer == null || string.IsNullOrEmpty(service.Consumer.Key))
            {
                throw new ArgumentException("Service does not have consumer key", "service");
            }

            this.ServiceRealm = serviceRealm;
            this.ConsumerKey  = service.Consumer.Key;
            this.EndUserId    = endUserId;
        }
Пример #2
0
 /// <summary>
 /// Creates a new OAuth protected requests.
 /// </summary>
 /// <remarks>
 /// Since neither a request token nor an access token is supplied,
 /// the user will have to authorize this request.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <returns>An OAuth protected request for the protected resource</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings)
 {
     return OAuthRequest.Create(
         resourceEndPoint,
         settings,
         new EmptyToken(settings.Consumer.Key, TokenType.Access),
         new EmptyToken(settings.Consumer.Key, TokenType.Request));
 }        
Пример #3
0
 /// <summary>
 /// Creates a new OAuth protected request configured for an ASP.NET context, 
 /// with the the current user or session id used as a state key.
 /// </summary>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback URI</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// configured for an ASP.NET context</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri)
 {
     return AspNetOAuthRequest.Create(
         resourceEndPoint,
         settings,
         callbackUri,
         GetEndUserIdFromHttpContextUser() ?? GetEndUserIdFromHttpSession());
 }
Пример #4
0
 /// <summary>
 /// Creates a new OAuth protected request configured for an ASP.NET context,
 /// with the the current user or session id used as a state key.
 /// </summary>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback URI</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// configured for an ASP.NET context</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri)
 {
     return(AspNetOAuthRequest.Create(
                resourceEndPoint,
                settings,
                callbackUri,
                GetEndUserIdFromHttpContextUser() ?? GetEndUserIdFromHttpSession()));
 }
Пример #5
0
 /// <summary>
 /// Creates a new OAuth protected requests.
 /// </summary>
 /// <remarks>
 /// Since neither a request token nor an access token is supplied,
 /// the user will have to authorize this request.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <returns>An OAuth protected request for the protected resource</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings)
 {
     return(OAuthRequest.Create(
                resourceEndPoint,
                settings,
                new EmptyToken(settings.Consumer.Key, TokenType.Access),
                new EmptyToken(settings.Consumer.Key, TokenType.Request)));
 }
Пример #6
0
 /// <summary>
 /// Creates a new OAuth protected request, initialised with previously
 /// retrieved request and access tokens, the specified callback
 /// </summary>
 /// <remarks>
 /// If the access token is valid, the user should not have to intervene
 /// to authorize the request and the protected resource should be
 /// fetched immediately.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback uri</param>
 /// <param name="requestToken">Request token</param>
 /// <param name="accessToken">Access token</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// initialised with the request token and access token</returns>
 public static OAuthRequest Create(
     EndPoint resourceEndPoint,
     OAuthService settings,
     Uri callbackUri,
     IToken requestToken,
     IToken accessToken)
 {
     return(OAuthRequest.Create(resourceEndPoint, settings, callbackUri, requestToken, null, accessToken));
 }
Пример #7
0
        /// <summary>
        /// Creates a new OAuth protected request configured for an ASP.NET context.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback URI</param>
        /// <param name="endUserId">End user ID</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// configured for an ASP.NET context</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string endUserId)
        {
            OAuthRequest request = OAuthRequest.Create(resourceEndPoint, settings, callbackUri, endUserId);

            request.AuthorizationHandler = AspNetOAuthRequest.HandleAuthorization;
            request.VerificationHandler  = AspNetOAuthRequest.HandleVerification;

            return(request);
        }
Пример #8
0
        /// <summary>
        /// Creates a new OAuth protected request configured for an ASP.NET context, 
        /// with the current URL as the callback URL and the current user or session id
        /// used as a state key.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// configured for an ASP.NET context</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings)
        {
            HttpContext context = HttpContext.Current;

            return AspNetOAuthRequest.Create(
                resourceEndPoint,
                settings,
                context.Request.Url,
                GetEndUserIdFromHttpContextUser() ?? GetEndUserIdFromHttpSession());
        }
Пример #9
0
        /// <summary>
        /// Creates a new OAuth protected request configured for an ASP.NET context,
        /// with the current URL as the callback URL and the current user or session id
        /// used as a state key.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// configured for an ASP.NET context</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings)
        {
            HttpContext context = HttpContext.Current;

            return(AspNetOAuthRequest.Create(
                       resourceEndPoint,
                       settings,
                       context.Request.Url,
                       GetEndUserIdFromHttpContextUser() ?? GetEndUserIdFromHttpSession()));
        }
Пример #10
0
        protected OAuthRequest(
            EndPoint resourceEndPoint,
            OAuthService settings,
            string verifier,
            RequestState state)
        {
            this.ResourceEndPoint     = resourceEndPoint;
            this.Service              = settings;
            this.RequestTokenVerifier = verifier;

            this.state = state;
        }
Пример #11
0
 /// <summary>
 /// Checks whether the supplied OAuthService is equal to this OAuthService object.
 /// </summary>
 /// <remarks>OAuthServices are compared property by property (excluding
 /// ComponentLocator).</remarks>
 /// <param name="other">Other OAuthService</param>
 /// <returns><c>true</c> if the OAuthServices' properties have the same values;
 /// <c>false</c> otherwise</returns>
 private bool Equals(OAuthService other)
 {
     return(other != null &&
            this.RequestTokenEndPoint.Equals(other.RequestTokenUrl) &&
            this.AuthorizationUrl.Equals(other.AuthorizationUrl) &&
            this.AccessTokenEndPoint.Equals(other.AccessTokenUrl) &&
            this.UseAuthorizationHeader == other.UseAuthorizationHeader &&
            string.Equals(this.Realm, other.Realm) &&
            string.Equals(this.SignatureMethod, other.SignatureMethod) &&
            string.Equals(this.OAuthVersion, other.OAuthVersion) &&
            this.Consumer.Equals(other.Consumer));
 }
Пример #12
0
        protected OAuthRequest(
            EndPoint resourceEndPoint,
            OAuthService settings,
            string verifier,
            IRequestStateStore stateStore,
            RequestStateKey stateKey)
        {
            this.ResourceEndPoint     = resourceEndPoint;
            this.Service              = settings;
            this.RequestTokenVerifier = verifier;

            this.stateStore = stateStore;
            this.state      = stateStore.Get(stateKey);
        }
Пример #13
0
        /// <summary>
        /// Creates a new OAuth protected request, using the supplied end user ID
        /// in combination with the service to create a state key to load and
        /// store request state such as tokens.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback URI</param>
        /// <param name="endUserId">End user ID</param>
        /// <param name="verifier">Verifier</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// initialised using the configured state store</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string verifier, string endUserId)
        {
            var stateStore = settings.ComponentLocator.GetInstance <IRequestStateStore>();

            var request = new OAuthRequest(
                resourceEndPoint,
                settings,
                verifier,
                stateStore,
                new RequestStateKey(settings, endUserId));

            request.CallbackUrl = callbackUri;

            return(request);
        }
Пример #14
0
 public FitbitService(System.Web.UI.Page page, System.Web.HttpContext context)
 {
     _page = page;
     _context = context;
     // Create OAuthService object, containing oauth consumer configuration
      _oAuthService = OAuthService.Create(
             new EndPoint(RequestTokenUrl, "POST"),         // requestTokenEndPoint
             new Uri(AuthorizationUrl),                     // authorizationUri
             new EndPoint(AccessTokenUrl, "POST"),          // accessTokenEndPoint
             true,                                          // useAuthorizationHeader
             "https://api.fitbit.com",                      // realm
             "HMAC-SHA1",                                   // signatureMethod
             "1.0",                                         // oauthVersion
             new OAuthConsumer(ConsumerKey, ConsumerSecret) // consumer
             );
 }
Пример #15
0
 /// <summary>
 /// Creates an OAuthService using defaults for most parameters, loading components
 /// from the current global service locator.
 /// </summary>
 /// <remarks>
 /// <para>The OAuthService created will have the following defaults:</para>
 /// <list type="table">
 ///     <listheader>
 ///         <term>Property</term>
 ///         <description>Value</description>
 ///     </listheader>
 ///     <item>
 ///         <term>HttpMethod</term>
 ///         <description><c>"POST"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>UseAuthorizationHeader</term>
 ///         <description><c>true</c></description>
 ///     </item>
 ///     <item>
 ///         <term>Realm</term>
 ///         <description><c>null</c></description>
 ///     </item>
 ///     <item>
 ///         <term>SignatureMethod</term>
 ///         <description><c>"HMAC-SHA1"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>OAuthVersion</term>
 ///         <description><c>"1.0"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>ConfigSection</term>
 ///         <description><c>"oauth.net.consumer"</c></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="requestTokenEndPoint">EndPoint for obtaining request tokens</param>
 /// <param name="authorizationUrl">URL to send users to for authorization</param>
 /// <param name="accessTokenEndPoint">EndPoint for obtaining access tokens</param>
 /// <param name="consumer">Consumer credentials</param>
 /// <returns>An OAuthService</returns>
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     IConsumer consumer)
 {
     return(OAuthService.Create(
                requestTokenEndPoint,
                authorizationUrl,
                accessTokenEndPoint,
                true,
                null,
                "HMAC-SHA1",
                Constants.Version1_0,
                consumer,
                () => ServiceLocator.Current));
 }
Пример #16
0
 /// <summary>
 /// Creates an OAuthService using defaults for most parameters, loading components
 /// from the service locator provided by the supplied provider.
 /// </summary>
 /// <remarks>
 /// <para>The OAuthService created will have the following defaults:</para>
 /// <list type="table">
 ///     <listheader>
 ///         <term>Property</term>
 ///         <description>Value</description>
 ///     </listheader>
 ///     <item>
 ///         <term>HttpMethod</term>
 ///         <description><c>"POST"</c></description>
 ///     </item>
 ///     <item>
 ///         <term>UseAuthorizationHeader</term>
 ///         <description><c>true</c></description>
 ///     </item>
 ///     <item>
 ///         <term>Realm</term>
 ///         <description><c>null</c></description>
 ///     </item>
 ///     <item>
 ///         <term>OAuthVersion</term>
 ///         <description><c>"1.0"</c></description>
 ///     </item>
 /// </list>
 /// </remarks>
 /// <param name="requestTokenEndPoint">EndPoint for obtaining request tokens</param>
 /// <param name="authorizationUrl">URL to send users to for authorization</param>
 /// <param name="accessTokenEndPoint">EndPoint for obtaining access tokens</param>
 /// <param name="signatureMethod">Signature method to use</param>
 /// <param name="consumer">Consumer credentials</param>
 /// <param name="serviceLocatorProvider">Service locator provider which provides
 /// a service locator for components</param>
 /// <returns>An OAuthService</returns>
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     string signatureMethod,
     IConsumer consumer,
     ServiceLocatorProvider serviceLocatorProvider)
 {
     return(OAuthService.Create(
                requestTokenEndPoint,
                authorizationUrl,
                accessTokenEndPoint,
                true,
                null,
                signatureMethod,
                Constants.Version1_0,
                consumer,
                serviceLocatorProvider));
 }
Пример #17
0
        /// <summary>
        /// Creates a new OAuth protected request, initialised with previously
        /// retrieved request and access tokens, the specified callback
        /// </summary>
        /// <remarks>
        /// If the access token is valid, the user should not have to intervene
        /// to authorize the request and the protected resource should be
        /// fetched immediately.
        /// </remarks>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback uri</param>
        /// <param name="requestToken">Request token</param>
        /// <param name="verifier">Verifier</param>
        /// <param name="accessToken">Access token</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// initialised with the request token and access token</returns>
        public static OAuthRequest Create(
            EndPoint resourceEndPoint,
            OAuthService settings,
            Uri callbackUri,
            IToken requestToken,
            string verifier,
            IToken accessToken)
        {
            var state = new RequestState(new RequestStateKey(settings, null))
            {
                RequestToken = requestToken,
                AccessToken  = accessToken
            };

            var request = new OAuthRequest(resourceEndPoint, settings, verifier, state);

            request.CallbackUrl = callbackUri;
            return(request);
        }
Пример #18
0
 public static OAuthService Create(
     EndPoint requestTokenEndPoint,
     Uri authorizationUrl,
     EndPoint accessTokenEndPoint,
     bool useAuthorizationHeader,
     string realm,
     string signatureMethod,
     string oauthVersion,
     IConsumer consumer)
 {
     return(OAuthService.Create(
                requestTokenEndPoint,
                authorizationUrl,
                accessTokenEndPoint,
                useAuthorizationHeader,
                realm,
                signatureMethod,
                oauthVersion,
                consumer,
                () => ServiceLocator.Current));
 }
Пример #19
0
 /// <summary>
 /// Creates a new OAuth protected request, initialised with a previously
 /// retrieved request token. This token may or may not have been authorized.
 /// </summary>
 /// <remarks>
 /// If the request token supplied has not been authorized, the user will
 /// have to be directed to authorize it before the request can proceed.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="requestToken">Request token</param>
 /// <returns>An OAuth protected request for the protected resource</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, IToken requestToken)
 {
     return(OAuthRequest.Create(resourceEndPoint, settings, requestToken, null));
 }
Пример #20
0
 /// <summary>
 /// Creates a new OAuth protected request, using the supplied end user ID
 /// in combination with the service to create a state key to load and 
 /// store request state such as tokens.
 /// </summary>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback URI</param>
 /// <param name="endUserId">End user ID</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// initialised using the configured state store</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string endUserId)
 {
     return OAuthRequest.Create(resourceEndPoint, settings, callbackUri, null, endUserId);
 }
Пример #21
0
        protected OAuthRequest(
           EndPoint resourceEndPoint,
           OAuthService settings,
           string verifier,
           RequestState state)
        {
            this.ResourceEndPoint = resourceEndPoint;
            this.Service = settings;
            this.RequestTokenVerifier = verifier;

            this.state = state;
        }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdsOAuthNetProvider"/>
 /// class.
 /// </summary>
 /// <param name="service">The OAuth service settings.</param>
 /// <param name="callbackUrl">The callback URL.</param>
 /// <param name="userId">A unique string to identify a user session. If
 /// this is a web application, this value could be
 /// <code>HttpContext.Current.Session.SessionID</code>.</param>
 protected AdsOAuthNetProvider(OAuthService service, string callbackUrl, string userId)
   : base(new EndPoint("http://localhost", "POST"), service, null,
       service.ComponentLocator.GetInstance<IRequestStateStore>(),
       new RequestStateKey(service, userId)) {
   this.CallbackUrl = (callbackUrl == null)? null : new Uri(callbackUrl);
   this.AuthorizationHandler = AspNetOAuthRequest.HandleAuthorization;
   this.VerificationHandler = AspNetOAuthRequest.HandleVerification;
 }
Пример #23
0
        protected OAuthRequest(
            EndPoint resourceEndPoint,
            OAuthService settings,
            string verifier,
            IRequestStateStore stateStore,
            RequestStateKey stateKey)
        {
            this.ResourceEndPoint = resourceEndPoint;
            this.Service = settings;
            this.RequestTokenVerifier = verifier;

            this.stateStore = stateStore;
            this.state = stateStore.Get(stateKey);
        }
Пример #24
0
        /// <summary>
        /// Creates a new OAuth protected request, using the supplied end user ID
        /// in combination with the service to create a state key to load and 
        /// store request state such as tokens.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback URI</param>
        /// <param name="endUserId">End user ID</param>
        /// <param name="verifier">Verifier</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// initialised using the configured state store</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string verifier, string endUserId)
        {
            var stateStore = settings.ComponentLocator.GetInstance<IRequestStateStore>();

            var request = new OAuthRequest(
                resourceEndPoint,
                settings,
                verifier,
                stateStore,
                new RequestStateKey(settings, endUserId));

            request.CallbackUrl = callbackUri;

            return request;
        }       
        public string Access(string url)
        {
            // Create OAuthService object, containing oauth consumer configuration
            service = OAuthService.Create(
                new EndPoint(RequestTokenUrl, "POST"),         // requestTokenEndPoint
                new Uri(AuthorizationUrl),                     // authorizationUri
                new EndPoint(AccessTokenUrl, "POST"),          // accessTokenEndPoint
                true,                                          // useAuthorizationHeader
                "http://wbsapi.withings.net",                       // realm
                "HMAC-SHA1",                                   // signatureMethod
                "1.0",                                         // oauthVersion
                new OAuthConsumer(ConsumerKey, ConsumerSecret) // consumer
                );
            string content;
            try
            {
                // Create OAuthRequest object, providing protected resource URL

                OAuthRequest request;
                if (m_bAuthorized)
                {
                    request = OAuthRequest.Create(
                        new EndPoint(url, "GET"),
                        service,
                        callbackurl,
                        requestToken, accessToken);

                }
                else
                {

                    request = OAuthRequest.Create(
                        new EndPoint(url, "GET"),
                        service,
                        callbackurl,
                        sessionId);

                }

                // Assign verification handler delegate
                request.VerificationHandler = AspNetOAuthRequest.HandleVerification;

                // Call OAuthRequest object GetResource method, which returns OAuthResponse object
                OAuthResponse response = request.GetResource();

                // Check if OAuthResponse object has protected resource
                if (!response.HasProtectedResource)
                {
                    m_bAuthorized = false;
                    // If not we are not authorized yet, build authorization URL and redirect to it
                    string authorizationUrl = service.BuildAuthorizationUrl(response.Token).AbsoluteUri;
                    return authorizationUrl;
                }
                else
                {
                    //Save our data
                    requestToken = request.RequestToken;
                    accessToken = request.AccessToken;

                }

                // Store the access token in session variable
                access_token = response.Token;

                // Initialize the XmlDocument object and OAuthResponse object's protected resource to it
                m_bAuthorized = true;

                Stream ms = response.ProtectedResource.GetResponseStream();
                // Jump to the start position of the stream
                ms.Seek(0, SeekOrigin.Begin);

                StreamReader rdr = new StreamReader(ms);
                string anwser_content = rdr.ReadToEnd();

                return anwser_content;
            }

            catch (OAuthRequestException ex)
            {
                return ex.Message;
            }
        }
Пример #26
0
        /// <summary>
        /// Creates a new OAuth protected request configured for an ASP.NET context.
        /// </summary>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback URI</param>
        /// <param name="endUserId">End user ID</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// configured for an ASP.NET context</returns>
        public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string endUserId)
        {
            OAuthRequest request = OAuthRequest.Create(resourceEndPoint, settings, callbackUri, endUserId);
            request.AuthorizationHandler = AspNetOAuthRequest.HandleAuthorization;
            request.VerificationHandler = AspNetOAuthRequest.HandleVerification;

            return request;
        }
Пример #27
0
        /// <summary>
        /// Creates a new OAuth protected request, initialised with previously
        /// retrieved request and access tokens, the specified callback  
        /// </summary>
        /// <remarks>
        /// If the access token is valid, the user should not have to intervene
        /// to authorize the request and the protected resource should be
        /// fetched immediately.
        /// </remarks>
        /// <param name="resourceEndPoint">Protected resource End Point</param>
        /// <param name="settings">Service settings</param>
        /// <param name="callbackUri">Callback uri</param>
        /// <param name="requestToken">Request token</param>
        /// <param name="verifier">Verifier</param>
        /// <param name="accessToken">Access token</param>
        /// <returns>An OAuth protected request for the protected resource,
        /// initialised with the request token and access token</returns>
        public static OAuthRequest Create(
            EndPoint resourceEndPoint,
            OAuthService settings,
            Uri callbackUri,
            IToken requestToken,
            string verifier,
            IToken accessToken)
        {
            var state = new RequestState(new RequestStateKey(settings, null))
            {
                RequestToken = requestToken,
                AccessToken = accessToken
            };

            var request = new OAuthRequest(resourceEndPoint, settings, verifier, state);
            request.CallbackUrl = callbackUri;
            return request;
        }
Пример #28
0
 /// <summary>
 /// Creates a new OAuth protected request, using the supplied end user ID
 /// in combination with the service to create a state key to load and
 /// store request state such as tokens.
 /// </summary>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback URI</param>
 /// <param name="endUserId">End user ID</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// initialised using the configured state store</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, Uri callbackUri, string endUserId)
 {
     return(OAuthRequest.Create(resourceEndPoint, settings, callbackUri, null, endUserId));
 }
Пример #29
0
        private OAuthResource ExecuteRequest(
            OAuthService service,
            NameValueCollection parameters,
            string uriFormat,
            string httpMethod,
            params string[] args)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            if (options.AuthorizationCallbackUri == null)
                throw new ArgumentException("AuthorizationCallbackUri option must not be null", "options");

            if (uriFormat == null)
                throw new ArgumentNullException("uriFormat");

            if (string.IsNullOrEmpty(uriFormat))
                throw new ArgumentException("uriFormat must not be empty", "uriFormat");

            var request = this.CreateRequest(service, uriFormat, httpMethod, args);

            var response = request.GetResource(parameters);

            return response.ProtectedResource;
        }
Пример #30
0
 /// <summary>
 /// Creates a new OAuth protected request, initialised with a previously
 /// retrieved request token. This token may or may not have been authorized.
 /// </summary>
 /// <remarks>
 /// If the request token supplied has not been authorized, the user will
 /// have to be directed to authorize it before the request can proceed.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="requestToken">Request token</param>
 /// <returns>An OAuth protected request for the protected resource</returns>
 public static OAuthRequest Create(EndPoint resourceEndPoint, OAuthService settings, IToken requestToken)
 {
     return OAuthRequest.Create(resourceEndPoint, settings, requestToken, null);
 }
Пример #31
0
        /// <summary>
        /// Creates an <see cref="OAuthRequest"/> for the specified resource
        /// </summary>
        /// <param name="service">OAuth service</param>
        /// <param name="uriFormat">Resource URI (optionally with format 
        /// placeholders)</param>
        /// <param name="args">Arguments to format with</param>
        /// <returns>
        /// <see cref="OAuthRequest"/> for the specified resource
        /// </returns>
        private OAuthRequest CreateRequest(
            OAuthService service,
            string uriFormat, 
            string httpMethod,
            params string[] args)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            if (uriFormat == null)
                throw new ArgumentNullException("uriFormat");

            if (string.IsNullOrEmpty(uriFormat))
                throw new ArgumentException("uriFormat must not be empty", "uriFormat");

            return AspNetOAuthRequest.Create(
                new OAuth.Net.Consumer.EndPoint(
                    string.Format(
                        CultureInfo.InvariantCulture, 
                        uriFormat, 
                        args), httpMethod),
                service,
                this.options.AuthorizationCallbackUri,
                HttpContext.Current.Session.SessionID);
        }
Пример #32
0
 /// <summary>
 /// Checks whether the supplied OAuthService is equal to this OAuthService object.
 /// </summary>
 /// <remarks>OAuthServices are compared property by property (excluding 
 /// ComponentLocator).</remarks>
 /// <param name="other">Other OAuthService</param>
 /// <returns><c>true</c> if the OAuthServices' properties have the same values;
 /// <c>false</c> otherwise</returns>
 private bool Equals(OAuthService other)
 {
     return other != null
         && this.RequestTokenEndPoint.Equals(other.RequestTokenUrl)
         && this.AuthorizationUrl.Equals(other.AuthorizationUrl)
         && this.AccessTokenEndPoint.Equals(other.AccessTokenUrl)                
         && this.UseAuthorizationHeader == other.UseAuthorizationHeader
         && string.Equals(this.Realm, other.Realm)
         && string.Equals(this.SignatureMethod, other.SignatureMethod)
         && string.Equals(this.OAuthVersion, other.OAuthVersion)
         && this.Consumer.Equals(other.Consumer);
 }
Пример #33
0
 /// <summary>
 /// Creates a new OAuth protected request, initialised with previously
 /// retrieved request and access tokens, the specified callback  
 /// </summary>
 /// <remarks>
 /// If the access token is valid, the user should not have to intervene
 /// to authorize the request and the protected resource should be
 /// fetched immediately.
 /// </remarks>
 /// <param name="resourceEndPoint">Protected resource End Point</param>
 /// <param name="settings">Service settings</param>
 /// <param name="callbackUri">Callback uri</param>
 /// <param name="requestToken">Request token</param>
 /// <param name="accessToken">Access token</param>
 /// <returns>An OAuth protected request for the protected resource,
 /// initialised with the request token and access token</returns>
 public static OAuthRequest Create(
     EndPoint resourceEndPoint,
     OAuthService settings,
     Uri callbackUri,
     IToken requestToken,
     IToken accessToken)
 {
     return OAuthRequest.Create(resourceEndPoint, settings, callbackUri, requestToken, null, accessToken);
 }