Exemplo n.º 1
0
        public override void Configure(IConfigSectionNode node)
        {
            base.Configure(node);

            var email = node.AttrByName(CFG_EMAIL).Value;
            var clientID = node.AttrByName(CFG_CLIENT_ID).Value;
            var clientSecret = node.AttrByName(CFG_CLIENT_SECRET).Value;

            var credentials = new PayPalCredentials(email, clientID, clientSecret);
            var token = new AuthenticationToken(PayPalSystem.PAYPAL_REALM, null); // OAuth token is empty at start
            User = new User(credentials, token, email, Rights.None);
        }
Exemplo n.º 2
0
        public override void Configure(IConfigSectionNode node)
        {
            base.Configure(node);

            var email        = node.AttrByName(CFG_EMAIL).Value;
            var clientID     = node.AttrByName(CFG_CLIENT_ID).Value;
            var clientSecret = node.AttrByName(CFG_CLIENT_SECRET).Value;

            var credentials = new PayPalCredentials(email, clientID, clientSecret);
            var token       = new AuthenticationToken(PayPalSystem.PAYPAL_REALM, null); // OAuth token is empty at start

            User = new User(credentials, token, email, Rights.None);
        }
Exemplo n.º 3
0
        internal PayPalOAuthToken generateOAuthToken(PayPalCredentials credentials)
        {
            var logID = Log(MessageType.Info, "generateOAuthToken()", "Generate OAuth token");

            try
            {
                var request = new WebClient.RequestParams(this)
                {
                    Method      = HTTPRequestMethod.POST,
                    ContentType = ContentType.FORM_URL_ENCODED,
                    Headers     = new Dictionary <string, string>
                    {
                        { HDR_AUTHORIZATION, credentials.AuthorizationHeader }
                    },
                    BodyParameters = new Dictionary <string, string>
                    {
                        { PRM_GRANT_TYPE, PRM_CLIENT_CREDENTIALS }
                    }
                };

                var response = WebClient.GetJson(URI_GenerateOAuthToken(), request);
                Log(MessageType.Trace, "generateOAuthToken()", response.ToJSON(), relatedMessageID: logID);
                Log(MessageType.Info, "generateOAuthToken()", "OAuth token generated", relatedMessageID: logID);
                return(new PayPalOAuthToken(
                           response["app_id"].AsString(),
                           response["expires_in"].AsInt(),
                           response["token_type"].AsString(),
                           response["access_token"].AsString(),
                           response["scope"].AsString(),
                           response["nonce"].AsString(),
                           m_OAuthExpirationMargin));
            }
            catch (Exception ex)
            {
                var error = composeError(StringConsts.PAYPAL_GENERATE_OAUTH_ERROR_MESSAGE.Args(ex.ToMessageWithType()), ex);
                Log(MessageType.Error, "generateOAuthToken()", error.Message, ex, relatedMessageID: logID);

                throw error;
            }
        }