AcquireRequestToken() public méthode

Acquire a request token, from the given URI, using the given HTTP method.

To use this method, first instantiate a new Oauth.Manager object, then set the callback param (oauth["callback"]='oob'). After the call returns, you should direct the user to open a browser window to the authorization page for the OAuth-enabled service. Or, you can automatically open that page yourself. Do this with System.Diagnostics.Process.Start(), passing the URL of the page. There should be one query param: oauth_token with the value obtained from oauth["token"].

According to the OAuth spec, you need to do this only ONCE per application. In other words, the first time the application is run. The normal oauth workflow is: (1) get a request token, (2) use that to acquire an access token (which requires explicit user approval), then (3) using that access token, invoke protected services. The first two steps need to be done only once per application.

For Twitter, at least, you can cache the access tokens indefinitely; Twitter says they never expire. However, other oauth services may not do the same. Also: the user may at any time revoke his authorization for your app, in which case you need to perform the first 2 steps again.

public AcquireRequestToken ( string uri, string method, string user_agent ) : OAuthResponse
uri string
method string
user_agent string
Résultat OAuthResponse
Exemple #1
0
 public string AuthenticateUser()
 {
     OAuth = new OAuth.Manager();
     OAuth["consumer_key"] = _ConsumerKey;
     OAuth["consumer_secret"] = _ConsumerSecret;
     OAuthResponse requestToken = OAuth.AcquireRequestToken("http://api.discogs.com/oauth/request_token", "POST", _UserAgent);
     string url = "http://www.discogs.com/oauth/authorize?oauth_token=" + OAuth["token"];
     return url;
 }
        public string AuthenticateUser()
        {
            OAuth = new OAuth.Manager();
            OAuth["consumer_key"]    = _ConsumerKey;
            OAuth["consumer_secret"] = _ConsumerSecret;
            OAuthResponse requestToken = OAuth.AcquireRequestToken("http://api.discogs.com/oauth/request_token", "POST", _UserAgent);
            string        url          = "http://www.discogs.com/oauth/authorize?oauth_token=" + OAuth["token"];

            return(url);
        }
        public bool AcquireRequestToken()
        {
            oAuth["token"]        = "";
            oAuth["token_secret"] = "";
            OAuthResponse responseTokenURI = oAuth.AcquireRequestToken(REQUEST_TOKEN_URI + SCOPES, "GET");

            if (responseTokenURI != null)
            {
                // Start default webbrowser to open authentification webpage
                System.Diagnostics.Process.Start(UnescapeAndExtractUri(responseTokenURI.AllText));
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task<bool?> Init(MetroWindow win)
        {
            try
            {
                parentWindow = win as MainWindow;

                authMgr = new Manager();
                authMgr["consumer_key"] = ConsumerKey;
                authMgr["consumer_secret"] = ConsumerSecret;
                authMgr.AcquireRequestToken(RequestTokenURL, "POST");
                MetroDialogSettings settings = new MetroDialogSettings()
                {
                    AnimateHide = true,
                    AnimateShow = true,
                    AffirmativeButtonText = "확인",
                    NegativeButtonText = "종료"
                };

                MessageDialogResult result = await DialogManager.ShowMessageAsync(parentWindow, "인증", "인증을 위해 웹브라우저를 통해 트위터에 로그인합니다.",
                    MessageDialogStyle.AffirmativeAndNegative, settings);

                if (result == MessageDialogResult.Affirmative)
                {
                    System.Diagnostics.Process.Start($"{RequestPinURL}{authMgr["token"]}");
                    settings = new MetroDialogSettings()
                    {
                        AnimateHide = true,
                        AnimateShow = true,
                        AffirmativeButtonText = "인증",
                        NegativeButtonText = "취소 및 종료"
                    };
                    
                    string pin = await DialogManager.ShowInputAsync(parentWindow, "PIN", "웹브라우저 상에 표시된 PIN을 입력합니다.", settings);

                    try
                    {
                        authMgr.AcquireAccessToken(AccessTokenURL, "POST", pin);
                    }
                    catch(Exception ex)
                    {
                        parentWindow.Close();
                    }

                    IsInit = true;

                    // Get Screen Name
                    dynamic obj = await GetJson("https://api.twitter.com/1.1/account/settings.json", "GET");
                    string name = obj.screen_name;

                    // GetProfile
                    dynamic json = await GetJson($"https://api.twitter.com/1.1/users/show.json?screen_name={name}", "GET");
                    parentWindow.UserNameBlock.Text = json.name;
                    parentWindow.ScreenNameBlock.Text = $"@{json.screen_name}";
                    parentWindow.ProfileDescBlock.Text = json.description;
                    string imageUrl = json.profile_image_url;
                    ProfileImage = new BitmapImage();
                    ProfileImage.BeginInit();
                    ProfileImage.UriSource = new Uri(imageUrl.Replace("_normal", ""));
                    ProfileImage.DownloadCompleted +=
                        (s, ev) => OnPropertyChanged("ProfileImage");
                    ProfileImage.EndInit();
                }
                else
                {
                    parentWindow.Close();
                }

                return IsInit;
            }
            catch (Exception e)
            {
                await DialogManager.ShowMessageAsync(parentWindow, "Error", $"= Message{e.Message}\n\n= Stack Trace\n{e.StackTrace}");
                IsInit = false;
                return false;
            }
        }