示例#1
0
        /// <summary>
        /// Called just before issuing request to third-party service when everything is ready.
        /// Allows to add extra parameters to request or do any other needed preparations.
        /// </summary>
        protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
        {
            // Source document
            // http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=12878032

            args.Request.AddParameter("application_key", _configuration.ClientPublic);
            args.Request.AddParameter("method", "users.getCurrentUser");

            // workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing 
            var fakeParam = new Parameter() { Name = "oauth_token", Value = AccessToken };
            args.Request.AddParameter(fakeParam);

            // Signing.
            // Call API methods using access_token instead of session_key parameter
            // Calculate every request signature parameter sig using a little bit different way described in
            // http://dev.odnoklassniki.ru/wiki/display/ok/Authentication+and+Authorization
            // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key)  )
            // Don't include access_token into request_params_composed_string
            string signature = string.Concat(args.Request.Parameters.OrderBy(x => x.Name).Select(x => string.Format("{0}={1}", x.Name, x.Value)).ToList());
            signature = (signature + (AccessToken + _configuration.ClientSecret).GetMd5Hash()).GetMd5Hash();

            // Removing fake param to prevent dups
            args.Request.Parameters.Remove(fakeParam);

            args.Request.AddParameter("access_token", AccessToken);
            args.Request.AddParameter("sig", signature);
        }
 /// <summary>
 /// Called just after obtaining response with access token from service.
 /// Allows to read extra data returned along with access token.
 /// </summary>
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
     // Instagram returns userinfo on access_token request
     // Source document 
     // http://instagram.com/developer/authentication/
     _accessTokenResponseContent = args.Response.GetContent();
 }
示例#3
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     // Source documents 
     // https://developer.foursquare.com/overview/auth.html
     // https://developer.foursquare.com/overview/versioning
     args.Request.AddParameter("v", System.DateTime.Now.ToString("yyyyMMdd"));
 }
示例#4
0
        /// <summary>
        /// Called just after obtaining response with access token from third-party service.
        /// Allows to read extra data returned along with access token.
        /// </summary>
        protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
        {
            var instance = JObject.Parse(args.Response.Content);
            _userId = instance["user_id"].Value<string>();
	    var email = instance["email"];
	    if (email != null)
	        _email = email.Value<string>();
        }
示例#5
0
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = null;
     args.Request.Parameters.Add(new Parameter
     {
         Name  = "oauth2_access_token",
         Type  = ParameterType.GetOrPost,
         Value = AccessToken
     });
 }
示例#6
0
 protected override void BeforeGetAccessToken(BeforeAfterRequestArgs args)
 {
     args.Request.AddObject(new
     {
         code = args.Parameters.GetOrThrowUnexpectedResponse("code"),
         client_id = args.Configuration.ClientId,
         client_secret = args.Configuration.ClientSecret,
         redirect_uri = args.Configuration.RedirectUri,
         state = State,
     });
 }
        /// <summary>
        /// Called just before issuing request to third-party service when everything is ready.
        /// Allows to add extra parameters to request or do any other needed preparations.
        /// </summary>
        protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
        {
            // Source documents
            // http://api.mail.ru/docs/guides/restapi/
            // http://api.mail.ru/docs/reference/rest/users.getInfo/

            args.Request.AddOrUpdateParameter("app_id", _configuration.ClientId);
            args.Request.AddOrUpdateParameter("method", "users.getInfo");
            args.Request.AddOrUpdateParameter("secure", "1");            
            args.Request.AddOrUpdateParameter("session_key", AccessToken);

            // workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing 
            var fakeParam = new Parameter { Name = "oauth_token", Value = AccessToken };
            args.Request.AddParameter(fakeParam);

            //sign=hex_md5('app_id={client_id}method=users.getInfosecure=1session_key={access_token}{secret_key}')
            string signature = string.Concat(args.Request.Parameters.OrderBy(x => x.Name).Select(x => string.Format("{0}={1}", x.Name, x.Value)).ToList());            
            signature = (signature+_configuration.ClientSecret).GetMd5Hash();

            args.Request.Parameters.Remove(fakeParam);

            args.Request.AddOrUpdateParameter("sig", signature);            
        }
 /// <summary>
 /// Called just after obtaining response with access token from service.
 /// Allows to read extra data returned along with access token.
 /// </summary>
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
      _accessUserInfo = args.Response.GetContent();
 }
示例#9
0
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = null;
     args.Request.Parameters.Add(new Parameter
     {
         Name = "token",
         Type = ParameterType.GetOrPost,
         Value = AccessToken
     });
     args.Request.AddParameter("resource_types", "[\"all\"]");
     base.BeforeGetUserInfo(args);
 }
示例#10
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     // Source document
     // http://api.yandex.com/oauth/doc/dg/yandex-oauth-dg.pdf
 }
示例#11
0
        /// <summary>
        /// It's required to store the User GUID obtained in the response for further usage
        /// https://developer.yahoo.com/oauth2/guide/flows_authcode/
        /// </summary>
        /// <param name="args"></param>
        protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
        {
            var responseJObject = JObject.Parse(args.Response.Content);

            this._userProfileGUID = responseJObject.SelectToken("xoauth_yahoo_guid")?.ToString();
        }
示例#12
0
 /// <summary>
 /// Called just after obtaining response with access token from third-party service.
 /// Allows to read extra data returned along with access token.
 /// </summary>
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
     var instance = JObject.Parse(args.Response.Content);
     _userId = instance["user_id"].Value<string>();
 }
示例#13
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("access_token", AccessToken);
 }
示例#14
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddHeader("Authorization", "Bearer " + AccessToken);
 }
示例#15
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("fields", "id,first_name,last_name,email,picture");
 }
示例#16
0
        protected override void BeforeGetAccessToken(BeforeAfterRequestArgs args)
        {
            var grantType = args.Parameters["grant_type"];

            if (string.IsNullOrWhiteSpace(grantType))
            {
                base.BeforeGetAccessToken(args);
            }
            else if (grantType == RefreshTokenKey)
            {
                args.Request.AddObject(new
                    {
                        refresh_token = args.Parameters.GetOrThrowUnexpectedResponse(RefreshTokenKey),
                        client_id = Configuration.ClientId,
                        client_secret = Configuration.ClientSecret,
                        grant_type = RefreshTokenKey
                    });
            }
        }
示例#17
0
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
     base.AfterGetAccessToken(args);
     //receiving args.Response & args.Parameters
     UserId = ParseTokenResponse(args.Response.Content, "user_id");
 }
示例#18
0
 /// <summary>
 /// Called just before building the request URI when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override async Task BeforeGetLoginLinkUri(BeforeAfterRequestArgs args)
 {
     await base.BeforeGetLoginLinkUri(args);
     // This allows us to get a refresh token
     args.Request.AddParameter("access_type", "offline");
 }
示例#19
0
 protected override void BeforeGetAccessToken(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new HttpBasicAuthenticator(Configuration.ClientId, Configuration.ClientSecret);
     base.BeforeGetAccessToken(args);
 }
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("access_token", AccessToken);
 }
示例#21
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("fields", "id,first_name,last_name,email,picture");
 }
示例#22
0
 /// <summary>
 /// Called just after obtaining response with access token from service.
 /// Allows to read extra data returned along with access token.
 /// </summary>
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
     _accessUserInfo = args.Response.GetContent();
 }
示例#23
0
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("fields", "id,first_name,last_name,email,picture,gender,location,age_range,birthday");
 }
示例#24
0
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
     base.BeforeGetUserInfo(args);
 }
示例#25
0
 protected override void BeforeGetAccessToken(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new HttpBasicAuthenticator(Configuration.ClientId, Configuration.ClientSecret);
     base.BeforeGetAccessToken(args);
 }
示例#26
0
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
      _accessToken = args.Response.Content;
 }
示例#27
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("opt_fields", "id,name,photo.image_128x128,photo.image_60x60,photo.image_36x36,email");
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
 }
示例#28
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     // workaround for current design, oauth_token is always present in URL, so we need emulate it for correct request signing
     var accessToken = new Parameter { Name = "access_token", Value = AccessToken };
     args.Request.AddParameter(accessToken);
 }
示例#29
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("uids", _userId);
     args.Request.AddParameter("fields", "uid,first_name,last_name,photo");
 }
示例#30
0
        protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
        {
            string token;

            try
            {
                // response can be sent in JSON format
                token = (string)JObject.Parse(args.Response.Content).SelectToken(RefreshTokenKey);
            }
            catch (JsonReaderException)
            {
                // or it can be in "query string" format (param1=val1&param2=val2)
                var collection = HttpUtility.ParseQueryString(args.Response.Content);

                token = collection[RefreshTokenKey];
            }

            if (!string.IsNullOrWhiteSpace(token))
            {
                RefreshToken = token;
            }

            base.AfterGetAccessToken(args);
        }
示例#31
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
 }
示例#32
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     // Source document
     // http://api.yandex.com/oauth/doc/dg/yandex-oauth-dg.pdf
 }
示例#33
0
 /// <summary>
 /// It's required to store the User GUID obtained in the response for further usage
 /// https://developer.yahoo.com/oauth2/guide/flows_authcode/
 /// </summary>
 /// <param name="args"></param>
 protected override void AfterGetAccessToken(BeforeAfterRequestArgs args)
 {
     var responseJObject = JObject.Parse(args.Response.Content);
     this._userProfileGUID = responseJObject.SelectToken("xoauth_yahoo_guid")?.ToString();
 }
示例#34
0
文件: VkClient.cs 项目: javaya/OAuth2
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("uids", _userId);
     args.Request.AddParameter("fields", "uid,first_name,last_name,photo");
 }
示例#35
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// 
 /// We have to reformat the Url adding the user guid for accessing their information
 /// https://developer.yahoo.com/oauth2/guide/apirequests/
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
     args.Request.Resource = string.Format(this.UserInfoServiceEndpoint.Resource, this._userProfileGUID);
 }
示例#36
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Request.AddParameter("opt_fields", "id,name,photo.image_128x128,photo.image_60x60,photo.image_36x36,email");
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
 }
示例#37
0
 /// <summary>
 /// Called just before issuing request to third-party service when everything is ready.
 /// Allows to add extra parameters to request or do any other needed preparations.
 ///
 /// We have to reformat the Url adding the user guid for accessing their information
 /// https://developer.yahoo.com/oauth2/guide/apirequests/
 /// </summary>
 protected override void BeforeGetUserInfo(BeforeAfterRequestArgs args)
 {
     args.Client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer");
     args.Request.Resource     = string.Format(this.UserInfoServiceEndpoint.Resource, this._userProfileGUID);
 }