示例#1
0
        public void GetAccessTokenWithValidExchangeToken_AccessTokenReturned()
        {
            var exchangeTokenRequest = new DTO.Request.FitBitExchangeTokenRequest
            {
                client_id     = "1234567",
                redirect_uri  = new System.Uri("localhost:5000/callback"),
                scope         = "activity",
                response_type = "code"
            };

            var retrievedExchangeToken = sut.GetExchangeToken(exchangeTokenRequest);

            retrievedExchangeToken.Result.Code.Should().NotBeNullOrEmpty();

            var accessTokenRequest = new DTO.Request.FitBitAccessTokenRequest
            {
                client_id    = "1234567",
                code         = retrievedExchangeToken.Result.Code,
                grant_type   = "authorization_code",
                redirect_uri = new System.Uri("localhost:5000/callback")
            };

            var retrievedAccessToken = sut.GetAccessToken(accessTokenRequest);

            retrievedAccessToken.Result.access_token.Should().NotBeNullOrEmpty();
            retrievedAccessToken.Result.refresh_token.Should().NotBeNullOrEmpty();
            retrievedAccessToken.Result.token_type.Should().Be("Bearer");
            retrievedAccessToken.Result.user_id.Should().Be("1234");
            retrievedAccessToken.Result.expires_in.Should().NotBe(null);
        }
示例#2
0
        public async Task <DTO.FitBitAuthenticationTokenResponse> GetAccessToken([FromQuery] DTO.Request.FitBitAccessTokenRequest request)
        {
            if (request.code == null || request.grant_type == null || request.redirect_uri == null)
            {
                return(new DTO.FitBitAuthenticationTokenResponse());
            }

            RandomNumberGenerator rng = new RNGCryptoServiceProvider();

            byte[] buffer0 = new byte[100];
            byte[] buffer1 = new byte[100];
            rng.GetBytes(buffer0);
            rng.GetBytes(buffer1);

            await Task.Delay(0);

            return(new DTO.FitBitAuthenticationTokenResponse
            {
                access_token = Convert.ToBase64String(buffer0),
                refresh_token = Convert.ToBase64String(buffer1),
                expires_in = 3600,
                token_type = "Bearer",
                user_id = "1234"
            });
        }