Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="config"></param>
        public AppStore(Config config) : base(config)
        {
            OAuthTokenServiceClient = SingletonStore <OAuthTokenV2ServiceClient>
                                      .Get(() => new OAuthTokenV2ServiceClient(Config));

            SyncSettingV2ServiceClient = SingletonStore <SyncSettingV2ServiceClient>
                                         .Get(() => new SyncSettingV2ServiceClient(Config));

            ServiceBusClient = SingletonStore <SQSServiceBusClient>
                               .Get(() => new SQSServiceBusClient(Config.ServiceBusClientConfig));

            SalesforceOAuthServiceClient = new SalesforceOAuthServiceClient(
                Config.SalesforceOAuthServiceClientConfig
                );

            OAuthTokenManager = new OAuthTokenManager(new OAuthTokenManagerConfig
            {
                IntegrationType    = CRMIntegrationTypes.Salesforce,
                AWSRegionEndpoint  = Config.AWSRegionEndpoint,
                AWSSecretKey       = Config.AWSSecretKey,
                AWSAccessKey       = Config.AWSAccessKey,
                AWSAccountId       = Config.AWSAccountId,
                OAuthServiceClient = SalesforceOAuthServiceClient,
                SlackAlertChannel  = Config.SlackAlertRefreshTokenChannel
            });

            if (!string.IsNullOrEmpty(Config.RedisConnectionString))
            {
                RedisDB = ConnectionMultiplexer.Connect(Config.RedisConnectionString).GetDatabase();
            }

            RemoteDataServiceClient = SingletonStore <RemoteDataServiceClient> .Get(
                () => new RemoteDataServiceClient(Config)
                );
        }
Example #2
0
        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (string.IsNullOrWhiteSpace(req.GetHeader("Authorization")) || req.GetHeader("Authorization").ToLower() == "null")
            {
                throw HttpError.Unauthorized("Authorization Header Missing");
            }

            var bearer = req.GetHeader("Authorization").Split(null).Last();

            if (string.IsNullOrWhiteSpace(bearer) || bearer.ToLower() == "null" || OAuthTokenManager.GetAuthenticationTicket(bearer) == null)
            {
                throw HttpError.Unauthorized("Unauthorized");
            }
        }
Example #3
0
        public async Task SendAsync_should_set_request_authorization()
        {
            var mockHttp   = new MockHttpMessageHandler();
            var httpClient = mockHttp.ToHttpClient();

            var discoveryRequest = Capture(mockHttp, "https://exemple.com/.well-known/openid-configuration");
            var jwksRequest      = Capture(mockHttp, "https://exemple.com/jwks");
            var tokenRequest     = Capture(mockHttp, "https://exemple.com/token");

            mockHttp.When("http://test")
            .WithHeaders("Authorization", "test test")
            .Respond(new StringContent("succeed"));

            discoveryRequest.SetResult(new
            {
                issuer         = "https://exemple.com",
                token_endpoint = "https://exemple.com/token",
                jwks_uri       = "https://exemple.com/jwks"
            });

            tokenRequest.SetResult(new
            {
                access_token = "test",
                token_type   = "test"
            });

            jwksRequest.SetResult(new
            {
            });

            var optionsMock = new Mock <IOptions <IdentityServerOptions> >();

            optionsMock.SetupGet(m => m.Value).Returns(new IdentityServerOptions
            {
                Authority = "https://exemple.com"
            });

            using var tokenManager = new OAuthTokenManager(httpClient, optionsMock.Object);

            var sut = new OAuthDelegatingHandler(tokenManager, mockHttp);

            var client = new HttpClient(sut);

            var response = await client.GetAsync("http://test");

            var content = await response.Content.ReadAsStringAsync();

            Assert.Equal("succeed", content);
        }
Example #4
0
        public AppStore(Config config) : base(config)
        {
            // service clients
            SyncSettingV2ServiceClient = SingletonStore <SyncSettingV2ServiceClient> .Get(
                () => new SyncSettingV2ServiceClient(Config)
                );

            RemoteDataServiceClient = SingletonStore <RemoteDataServiceClient> .Get(
                () => new RemoteDataServiceClient(Config)
                );

            ContactsServiceClient = SingletonStore <ContactsServiceClient> .Get(
                () => new ContactsServiceClient(new ContactsServiceConfig
            {
                ApiEndpoint = Config.ContactsServiceApiEndpoint
            })
                );

            SalesforceOAuthServiceClient = new SalesforceOAuthServiceClient(
                Config.SalesforceOAuthServiceClientConfig
                );
            OAuthTokenManager = new OAuthTokenManager(new OAuthTokenManagerConfig
            {
                IntegrationType    = CRMIntegrationTypes.Salesforce,
                AWSRegionEndpoint  = Config.AWSRegionEndpoint,
                AWSSecretKey       = Config.AWSSecretKey,
                AWSAccessKey       = Config.AWSAccessKey,
                AWSAccountId       = Config.AWSAccountId,
                OAuthServiceClient = SalesforceOAuthServiceClient,
                SlackAlertChannel  = Config.SlackAlertRefreshTokenChannel
            });

            // comparers
            SalesforceTopicMappingComparer = SingletonStore <SalesforceTopicMappingComparer> .Get(
                () => new SalesforceTopicMappingComparer()
                );
        }
Example #5
0
 /// <summary>
 /// Creates a new token manager in the current client configuration with a pre-shared token or a token from a previous session.
 /// </summary>
 /// <param name="appId">The app id of this client, in the form of {customer_id}-{client_id}</param>
 /// <param name="appSecret">The app secret of this client</param>
 /// <param name="accessToken">The pre-shared access token (typically of the Sync User) or an already existing access token from a previous session</param>
 /// <param name="refreshToken">The pre-shared refresh token (typically of the Sync User) or an already existing refresh token from a previous session</param>
 /// <param name="expiresOn">The expiration date of the access token</param>
 /// <returns></returns>
 public OAuthTokenManager CreateOAuthTokenManager(string appId, string appSecret, string accessToken, string refreshToken, DateTime expiresOn)
 {
     OAuthTokenManager = new Authentication.OAuthTokenManager(this, appId, appSecret, accessToken, refreshToken, expiresOn);
     return(OAuthTokenManager);
 }
Example #6
0
 /// <summary>
 /// Creates a new token manager in the current client configuration with a pre-shared token or a token from a previous session.
 /// </summary>
 /// <param name="appId">The app id of this client, in the form of {customer_id}-{client_id}</param>
 /// <param name="appSecret">The app secret of this client</param>
 /// <param name="accessToken">The pre-shared access token (typically of the Sync User) or an already existing access token from a previous session</param>
 /// <returns></returns>
 public OAuthTokenManager CreateOAuthTokenManager(string appId, string appSecret, string accessToken)
 {
     OAuthTokenManager = new Authentication.OAuthTokenManager(this, appId, appSecret, accessToken);
     return(OAuthTokenManager);
 }
Example #7
0
 /// <summary>
 /// Sets the OAuth Token Manager of this client configuration
 /// </summary>
 /// <param name="oauthTokenManager"></param>
 public void SetOAuthTokenManager(OAuthTokenManager oauthTokenManager)
 {
     OAuthTokenManager = oauthTokenManager;
 }
Example #8
0
 /// <summary>
 /// Creates a new client configuration with the specified API URL
 /// </summary>
 /// <param name="baseUrl">The base URL of the API</param>
 /// <param name="oauthTokenManager">The OAuth Token Manager</param>
 public HQAPIClientConfiguration(string baseUrl, OAuthTokenManager oauthTokenManager)
     : this(baseUrl)
 {
     OAuthTokenManager = oauthTokenManager;
 }