private OAuthResponse FetchToken(OAuthEnvironment environment, String requestPayload, TokenType tokenType) { //Get credentials CredentialUtil.Credentials credentials = GetCredentials(environment); //Initialize client RestClient client = new RestClient { BaseUrl = new Uri(environment.ApiEndpoint()) }; //Create request RestRequest request = new RestRequest(Method.POST); //Add headers request.AddHeader(Constants.HEADER_AUTHORIZATION, OAuth2Util.CreateAuthorizationHeader(credentials)); //Set request payload request.AddParameter(Constants.HEADER_CONTENT_TYPE, requestPayload, ParameterType.RequestBody); //Call the API IRestResponse response = client.Execute(request); //Parse response OAuthResponse oAuthResponse = HandleApiResponse(response, tokenType); return(oAuthResponse); }
public void CreateAuthorizationHeader_Success() { String path = @"../../../ebay-config-sample.yaml"; CredentialUtil.Load(path); CredentialUtil.Credentials credentials = CredentialUtil.GetCredentials(OAuthEnvironment.PRODUCTION); String authorizationHeader = OAuth2Util.CreateAuthorizationHeader(credentials); Assert.NotNull(authorizationHeader); Boolean headerStartsWithBasic = authorizationHeader.StartsWith("Basic ", StringComparison.Ordinal); Assert.True(headerStartsWithBasic); }