Esempio n. 1
0
        public IRestRequest SignRequest(IRestRequest restRequest, RestClient restClient, string contentType)
        {
            // Seller APIs
            LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials
            {
                ClientId     = ClientId,
                ClientSecret = ClientSecret,
                RefreshToken = RefreshToken,
                Endpoint     = Endpoint
            };
            AWSAuthenticationCredentials awsAuthenticationCredentials = new AWSAuthenticationCredentials
            {
                AccessKeyId = AccessKeyId,
                SecretKey   = SecretKey,
                Region      = Region
            };

            restRequest = new AWSSigV4Signer(awsAuthenticationCredentials)
                          .Sign(restRequest, restClient.BaseUrl.Host);

            restRequest.AddHeader("Content-type", contentType);

            restRequest.AddHeader("user-agent", "My YouTube App 1.0 (Language=csharp;Platform=Windows/10)");

            return(restRequest);
        }
        public void LWAAuthorizationCredentialsWithScopesBuildsSellerlessTokenRequestMeta()
        {
            LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials()
            {
                ClientId     = TestClientId,
                ClientSecret = TestClientSecret,
                Endpoint     = TestUri,
                Scopes       = new List <string>()
                {
                    ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI
                }
            };

            LWAAccessTokenRequestMeta expected = new LWAAccessTokenRequestMeta()
            {
                ClientId     = TestClientId,
                ClientSecret = TestClientSecret,
                GrantType    = LWAAccessTokenRequestMetaBuilder.SellerlessAPIGrantType,
                Scope        = string.Format("{0} {1}", ScopeConstants.ScopeMigrationAPI, ScopeConstants.ScopeNotificationsAPI),
                RefreshToken = null
            };

            LWAAccessTokenRequestMeta actual = lwaAccessTokenRequestMetaBuilderUnderTest.Build(lwaAuthorizationCredentials);

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        private static IRestRequest SignWithAccessToken(IRestRequest restRequest, string clientId, string clientSecret, string refreshToken)
        {
            var lwaAuthorizationCredentials = new LWAAuthorizationCredentials
            {
                ClientId     = clientId,
                ClientSecret = clientSecret,
                Endpoint     = new Uri(AUTH_ENDPOINT),
                RefreshToken = refreshToken,
            };

            return(new LWAAuthorizationSigner(lwaAuthorizationCredentials).Sign(restRequest));
        }
Esempio n. 4
0
        public string GetToken()
        {
            LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials
            {
                ClientId     = ClientId,
                ClientSecret = ClientSecret,
                RefreshToken = RefreshToken,
                Endpoint     = Endpoint
            };

            var requestTokenClient = new LWAClient(lwaAuthorizationCredentials);

            return(requestTokenClient.GetAccessToken());
        }
        public void LWAAuthorizationCredentialsWithoutScopesBuildsSellerTokenRequestMeta()
        {
            LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials()
            {
                ClientId     = TestClientId,
                ClientSecret = TestClientSecret,
                Endpoint     = TestUri,
                RefreshToken = TestRefreshToken
            };

            LWAAccessTokenRequestMeta expected = new LWAAccessTokenRequestMeta()
            {
                ClientId     = TestClientId,
                ClientSecret = TestClientSecret,
                GrantType    = LWAAccessTokenRequestMetaBuilder.SellerAPIGrantType,
                RefreshToken = TestRefreshToken,
                Scope        = null
            };

            LWAAccessTokenRequestMeta actual = lwaAccessTokenRequestMetaBuilderUnderTest.Build(lwaAuthorizationCredentials);

            Assert.Equal(expected, actual);
        }