public async Task GetRequestToken(TwitterApplication application) { this.application = application; var data = await TwitterClient.Current.GetRequestToken(this.application.ConsumerKey, this.application.ConsumerSecret).ToTask(); this.requestToken = data.Token; Process.Start(data.AuthorizeUrl.ToString()); }
public IObservable<string> Request() { return authorizer.GetRequestToken(requestTokenUrl) .ToObservable() .Do(x => requestToken = x.Token) .Select(x => authorizer.BuildAuthorizeUrl(authorizeUrl, x.Token)); }
public void Initialize() { _authorizer = new OAuthAuthorizer(Setting.GlobalConsumerKey.Value ?? App.ConsumerKey, Setting.GlobalConsumerSecret.Value ?? App.ConsumerSecret); CurrentAuthenticationStep = AuthenticationStep.RequestingToken; Observable.Defer(() => _authorizer.GetRequestToken(RequestTokenEndpoint).ToObservable()) .Retry(3, TimeSpan.FromSeconds(3)) // twitter sometimes returns an error without any troubles. .Subscribe(t => { _currentRequestToken = t.Token; CurrentAuthenticationStep = AuthenticationStep.WaitingPinInput; BrowserHelper.Open(_authorizer.BuildAuthorizeUrl(AuthorizationEndpoint, t.Token)); }, ex => this.Messenger.Raise(new TaskDialogMessage( new TaskDialogOptions { Title = "OAuth認証エラー", MainIcon = VistaTaskDialogIcon.Error, MainInstruction = "Twitterと正しく通信できませんでした。", Content = "何度も繰り返し発生する場合は、しばらく時間を置いて試してみてください。", CommonButtons = TaskDialogCommonButtons.Close, FooterIcon = VistaTaskDialogIcon.Information, FooterText = "コンピュータの時計が大幅にずれている場合も認証が行えないことがあります。" }))); }
public void Initialize() { _authorizer = new OAuthAuthorizer(Setting.GlobalConsumerKey.Value ?? App.ConsumerKey, Setting.GlobalConsumerSecret.Value ?? App.ConsumerSecret); CurrentAuthenticationStep = AuthenticationStep.RequestingToken; Observable.Defer(() => _authorizer.GetRequestToken(RequestTokenEndpoint).ToObservable()) .Retry(3, TimeSpan.FromSeconds(3)) // twitter sometimes returns an error without any troubles. .Subscribe( t => { _currentRequestToken = t.Token; CurrentAuthenticationStep = AuthenticationStep.WaitingPinInput; BrowserHelper.Open(_authorizer.BuildAuthorizeUrl(AuthorizationEndpoint, t.Token)); }, ex => this.Messenger.RaiseSafe(() => new TaskDialogMessage(new TaskDialogOptions { Title = AuthorizationWindowResources.OAuthErrorTitle, MainIcon = VistaTaskDialogIcon.Error, MainInstruction = AuthorizationWindowResources.OAuthErrorInst, Content = AuthorizationWindowResources.OAuthErrorContent, CommonButtons = TaskDialogCommonButtons.Close, FooterIcon = VistaTaskDialogIcon.Information, FooterText = AuthorizationWindowResources.OAuthErrorFooter, }))); }
public async Task <AuthCredential> ProcessApprovedAuthCallbackAsync(RequestToken token) { if (token == null) { throw new ArgumentNullException("token", "RequestToken cannot be null"); } if (string.IsNullOrWhiteSpace(token.Token)) { throw new ArgumentNullException("token", "RequestToken.Token must not be null"); } var oauthRequestToken = new AsyncOAuth.RequestToken(token.Token, token.Secret); var authorizer = new OAuthAuthorizer(ConsumerKey, ConsumerSecret); var accessToken = await authorizer.GetAccessToken(Constants.BaseApiUrl + Constants.TemporaryCredentialsAccessTokenUri, oauthRequestToken, token.Verifier); var result = new AuthCredential { AuthToken = accessToken.Token.Key, AuthTokenSecret = accessToken.Token.Secret, UserId = accessToken.ExtraData["encoded_user_id"].FirstOrDefault() }; return(result); }
public string GetPinRequestUrl(string requestTokenUrl, string authorizeUrl) { // get request token var request = _authorizer.GetRequestToken(requestTokenUrl); //request.Start(); //request.Wait(); _requestToken = request.Result.Token; return _authorizer.BuildAuthorizeUrl(authorizeUrl, _requestToken); }
/// <summary> /// This method should be called once you have received the verifier from /// Evernote. It will populate a EvernoteCredentials object with all the /// information you need to authenticate to Evernote as this user /// </summary> /// <remarks> /// This is an asynchronous method /// </remarks> /// <param name="oauth_verifier">The verifier passed in via the QueryString to your endpoint</param> /// <param name="token">The token used to request the authorization - this should be persisted from the call to GetRequestToken</param> /// <returns></returns> public EvernoteCredentials ParseAccessToken(string oauth_verifier, RequestToken token) { return Task.Run(() => AsyncEvernoteAuthorizer.ParseAccessToken(oauth_verifier, token)).Result; }
/// <summary> /// Returns a URL that you can redirect the user to on the Evernote site that /// will prompt them to authroize your app. Once they do this, they will /// be redirected to callbackUri with the oauth_validator parameter /// </summary> /// <param name="callbackUri">The end point you plan on using to call ParseAccessToken</param> /// <returns></returns> public string BuildAuthorizeUrl(RequestToken token) { return AsyncEvernoteAuthorizer.BuildAuthorizeUrl(token); }
/// <summary>asynchronus get GetAccessToken</summary> public Task <TokenResponse <AccessToken> > GetAccessToken(string accessTokenUrl, RequestToken requestToken, string verifier, IEnumerable <KeyValuePair <string, string> > parameters = null, HttpContent postValue = null) { Precondition.NotNull(accessTokenUrl, "accessTokenUrl"); Precondition.NotNull(requestToken, "requestToken"); Precondition.NotNull(verifier, "verifier"); var verifierParam = new KeyValuePair <string, string>("oauth_verifier", verifier.Trim()); if (parameters == null) { parameters = Enumerable.Empty <KeyValuePair <string, string> >(); } var handler = new OAuthMessageHandler(consumerKey, consumerSecret, token: requestToken, optionalOAuthHeaderParameters: parameters.Concat(new[] { verifierParam })); return(GetTokenResponse(accessTokenUrl, handler, postValue, (key, secret) => new AccessToken(key, secret))); }
public async Task<string> AuthorizeUri() { requestToken = (await authorizer.GetRequestToken(requestUrl)).Token; return authorizer.BuildAuthorizeUrl(authorizeUrl, requestToken); }