/*
         * Use this operation to get the Authorization URL to redirect the user to.
         * Once the user authenticates and approves the consent, the callback need to be
         * captured by the redirect URL setup by the app
         */
        public String GenerateUserAuthorizationUrl(OAuthEnvironment environment, IList <String> scopes, String state)
        {
            //Validate request
            ValidateEnvironmentAndScopes(environment, scopes);

            //Get credentials
            CredentialUtil.Credentials credentials = GetCredentials(environment);

            //Format scopes
            String formattedScopes = OAuth2Util.FormatScopesForRequest(scopes);

            //Prepare URL
            StringBuilder sb = new StringBuilder();

            sb.Append(environment.WebEndpoint()).Append("?");

            //Prepare request payload
            Dictionary <String, String> queryParams = new Dictionary <string, string>
            {
                { Constants.PAYLOAD_CLIENT_ID, credentials.Get(CredentialType.APP_ID) },
                { Constants.PAYLOAD_RESPONSE_TYPE, Constants.PAYLOAD_VALUE_CODE },
                { Constants.PAYLOAD_REDIRECT_URI, credentials.Get(CredentialType.REDIRECT_URI) },
                { Constants.PAYLOAD_SCOPE, formattedScopes }
            };

            if (state != null)
            {
                queryParams.Add(Constants.PAYLOAD_STATE, state);
            }

            sb.Append(OAuth2Util.CreateRequestPayload(queryParams));

            log.Debug("Authorization url " + sb);
            return(sb.ToString());
        }
Пример #2
0
        /*
         * Create Base64 encoded Authorization header value
         */
        public static String CreateAuthorizationHeader(CredentialUtil.Credentials credentials)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(credentials.Get(CredentialType.APP_ID)).Append(Constants.CREDENTIAL_DELIMITER);
            stringBuilder.Append(credentials.Get(CredentialType.CERT_ID));
            var    plainTextBytes = Encoding.UTF8.GetBytes(stringBuilder.ToString());
            string encodedText    = Convert.ToBase64String(plainTextBytes);

            return(Constants.HEADER_PREFIX_BASIC + encodedText);
        }
Пример #3
0
        public void GetCredentials_Success()
        {
            String path = @"../../../ebay-config-sample.yaml";

            CredentialUtil.Load(path);
            CredentialUtil.Credentials credentials = CredentialUtil.GetCredentials(OAuthEnvironment.PRODUCTION);
            Assert.NotNull(credentials);
            Assert.NotNull(credentials.Get(CredentialType.APP_ID));
            Assert.NotNull(credentials.Get(CredentialType.DEV_ID));
            Assert.NotNull(credentials.Get(CredentialType.CERT_ID));
            Assert.NotNull(credentials.Get(CredentialType.REDIRECT_URI));
        }
        /*
         * Use this operation to get the refresh and access tokens.
         */
        public OAuthResponse ExchangeCodeForAccessToken(OAuthEnvironment environment, String code)
        {
            //Validate request
            ValidateInput("Environment", environment);
            ValidateInput("Code", code);

            //Get credentials
            CredentialUtil.Credentials credentials = GetCredentials(environment);

            // Create request payload
            Dictionary <String, String> payloadParams = new Dictionary <string, string>
            {
                { Constants.PAYLOAD_GRANT_TYPE, Constants.PAYLOAD_VALUE_AUTHORIZATION_CODE },
                { Constants.PAYLOAD_REDIRECT_URI, credentials.Get(CredentialType.REDIRECT_URI) },
                { Constants.PAYLOAD_CODE, code }
            };
            String requestPayload = OAuth2Util.CreateRequestPayload(payloadParams);

            OAuthResponse oAuthResponse = FetchToken(environment, requestPayload, TokenType.USER);

            return(oAuthResponse);
        }