Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 /// <summary>
 /// For Desktop authentication. Your code should direct the user to the FitBit website to get
 /// Their pin, they can then enter it here.
 /// </summary>
 /// <param name="pin"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public async Task<AuthCredential> GetAuthCredentialFromPinAsync(string pin, RequestToken token)
 {
     var oauthRequestToken = new AsyncOAuth.RequestToken(token.Token, token.Secret);
     var authorizer = new OAuthAuthorizer(ConsumerKey, ConsumerSecret);
     var accessTokenResponse = await authorizer.GetAccessToken(Constants.BaseApiUrl + Constants.TemporaryCredentialsAccessTokenUri, oauthRequestToken, pin);
     // save access token.
     var accessToken = accessTokenResponse.Token;
     return new AuthCredential
     {
         AuthToken = accessToken.Key,
         AuthTokenSecret = accessToken.Secret
     };
 }
Exemplo n.º 3
0
        /// <summary>
        /// For Desktop authentication. Your code should direct the user to the FitBit website to get
        /// Their pin, they can then enter it here.
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <AuthCredential> GetAuthCredentialFromPinAsync(string pin, RequestToken token)
        {
            var oauthRequestToken   = new AsyncOAuth.RequestToken(token.Token, token.Secret);
            var authorizer          = new OAuthAuthorizer(ConsumerKey, ConsumerSecret);
            var accessTokenResponse = await authorizer.GetAccessToken(Constants.BaseApiUrl + Constants.TemporaryCredentialsAccessTokenUri, oauthRequestToken, pin);

            // save access token.
            var accessToken = accessTokenResponse.Token;

            return(new AuthCredential
            {
                AuthToken = accessToken.Key,
                AuthTokenSecret = accessToken.Secret
            });
        }
Exemplo n.º 4
0
        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;
        }