Ejemplo n.º 1
0
 public FhirClient(
     HttpClient httpClient,
     TestFhirServer testFhirServer,
     ResourceFormat format,
     TestApplication clientApplication,
     TestUser user,
     (bool SecurityEnabled, string AuthorizeUrl, string TokenUrl) securitySettings)
Ejemplo n.º 2
0
        private async Task Authenticate(TestApplication clientApplication, TestUser user)
        {
            if (clientApplication.Equals(TestApplications.InvalidClient))
            {
                return;
            }

            if (user == null)
            {
                string scope    = clientApplication.Equals(TestApplications.WrongAudienceClient) ? clientApplication.ClientId : AuthenticationSettings.Scope;
                string resource = clientApplication.Equals(TestApplications.WrongAudienceClient) ? clientApplication.ClientId : AuthenticationSettings.Resource;

                await this.AuthenticateOpenIdClientCredentials(
                    clientApplication.ClientId,
                    clientApplication.ClientSecret,
                    resource,
                    scope,
                    cancellationToken : default);
            }
            else
            {
                await this.AuthenticateOpenIdUserPassword(
                    clientApplication.ClientId,
                    clientApplication.ClientSecret,
                    AuthenticationSettings.Resource,
                    AuthenticationSettings.Scope,
                    user.UserId,
                    user.Password,
                    cancellationToken : default);
            }
        }
Ejemplo n.º 3
0
 public TestFhirClient(
     HttpClient httpClient,
     TestFhirServer testFhirServer,
     ResourceFormat format,
     TestApplication clientApplication,
     TestUser user)
     : base(httpClient, format)
 {
     _testFhirServer    = testFhirServer;
     _clientApplication = clientApplication;
     _user = user;
 }
Ejemplo n.º 4
0
        public TestFhirClient(
            HttpClient httpClient,
            TestFhirServer testFhirServer,
            ResourceFormat format,
            TestApplication clientApplication,
            TestUser user)
            : base(httpClient, format)
        {
            _testFhirServer    = testFhirServer;
            _clientApplication = clientApplication;
            _user = user;

            ConfigureSecurityOptions().GetAwaiter().GetResult();
            SetupAuthenticationAsync(clientApplication, user).GetAwaiter().GetResult();
        }
Ejemplo n.º 5
0
        private async Task SetupAuthenticationAsync(TestApplication clientApplication, TestUser user = null)
        {
            if (SecurityEnabled == true)
            {
                var tokenKey = $"{clientApplication.ClientId}:{(user == null ? string.Empty : user.UserId)}";

                if (!_bearerTokens.ContainsKey(tokenKey))
                {
                    await Authenticate(clientApplication, user);

                    _bearerTokens[tokenKey] = HttpClient.DefaultRequestHeaders?.Authorization?.Parameter;
                }
                else
                {
                    SetBearerToken(_bearerTokens[tokenKey]);
                }
            }
        }
Ejemplo n.º 6
0
 public TestFhirClient CreateClientForClientApplication(TestApplication clientApplication)
 {
     EnsureArg.IsNotNull(clientApplication, nameof(clientApplication));
     return(_testFhirServer.GetTestFhirClient(Format, clientApplication, null));
 }
Ejemplo n.º 7
0
 public TestFhirClient CreateClientForUser(TestUser user, TestApplication clientApplication)
 {
     EnsureArg.IsNotNull(user, nameof(user));
     EnsureArg.IsNotNull(clientApplication, nameof(clientApplication));
     return(_testFhirServer.GetTestFhirClient(Format, clientApplication, user));
 }