public void QueryParameterAccessMethod_GetAccessToken()
        {
            // No query parameter at all.
            var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com"));
            var accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.IsNullOrEmpty(accessToken);

            // Different query parameter.
            request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?a=1"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.IsNullOrEmpty(accessToken);

            // One query parameter and it's access_token.
            request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?a=1&access_token=abc"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.That(accessToken, Is.EqualTo("abc"));

            // 2 query parameters and one of them is access_token.
            request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?access_token=abc"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.That(accessToken, Is.EqualTo("abc"));
        }
Exemple #2
0
        public void QueryParameterAccessMethod_GetAccessToken()
        {
            // No query parameter at all.
            var request     = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com"));
            var accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);

            Assert.That(accessToken, Is.Null.Or.Empty);

            // Different query parameter.
            request     = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?a=1"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.That(accessToken, Is.Null.Or.Empty);

            // One query parameter and it's access_token.
            request     = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?a=1&access_token=abc"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.That(accessToken, Is.EqualTo("abc"));

            // 2 query parameters and one of them is access_token.
            request     = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sample.com?access_token=abc"));
            accessToken = new BearerToken.QueryParameterAccessMethod().GetAccessToken(request);
            Assert.That(accessToken, Is.EqualTo("abc"));
        }