/// <summary>Initializes a new instance of the <see cref="AccessTokenLoader" /> class.</summary> /// <param name="projects">The projects.</param> /// <param name="samlAuthenticator">The saml authenticator.</param> /// <param name="oAuthClientFactory">The o authentication client factory.</param> /// <param name="serviceProvider">The service provider.</param> /// <exception cref="ArgumentNullException"><paramref name="projects"/> /// or /// <paramref name="samlAuthenticator"/> /// or /// <paramref name="oAuthClientFactory"/> /// or /// <paramref name="serviceProvider"/> is null. /// </exception> public AccessTokenLoader( ProjectConfigurationCollection projects, ISamlAuthenticator samlAuthenticator, IOAuthClientFactory oAuthClientFactory, IServiceProvider serviceProvider) { _projects = projects ?? throw new ArgumentNullException(nameof(projects)); _samlAuthenticator = samlAuthenticator ?? throw new ArgumentNullException(nameof(samlAuthenticator)); _oAuthClientFactory = oAuthClientFactory ?? throw new ArgumentNullException(nameof(oAuthClientFactory)); _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); }
/// <summary> /// Creates a <see cref="ProjectAccessTokenHealthCheck"/> for the specified project. /// </summary> /// <param name="project">The project.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">project</exception> public ProjectAccessTokenHealthCheck Create(ProjectConfiguration project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } ISamlAuthenticator samlAuthenticator = _serviceProvider.GetRequiredService <ISamlAuthenticator>(); IOAuthClientFactory oauthClientFactory = _serviceProvider.GetRequiredService <IOAuthClientFactory>(); return(new ProjectAccessTokenHealthCheck(project, samlAuthenticator, oauthClientFactory)); }
private static void ConfigureDynamics(IServiceCollection services, ProjectConfiguration project, ProjectResource projectResource, Serilog.ILogger logger) { Debug.Assert(services != null, "Required ServiceCollection is null"); Debug.Assert(project != null, "Required ProjectConfiguration is null"); Debug.Assert(projectResource != null, "Required ProjectResource is null"); Debug.Assert(projectResource.Type == ProjectType.Dynamics, "Project type must be Dynamics"); // the projectResourceKey convention is repeated also in OAuthClientFactory which gets the HttpClient using the same convention, // // {Id}-dynamics-authorization // string projectResourceKey = project.Id + "-dynamics"; // add authorization HttpClient services.AddHttpClient(projectResourceKey + "-authorization", configure => configure.BaseAddress = projectResource.AuthorizationUri) ; // add odata HttpClient // note: I do not like this IoC anti-pattern where we are using the service locator directly, however, // there are many named dependencies. There may be an opportunity to address this in the future var builder = services.AddHttpClient(projectResourceKey, configure => { configure.BaseAddress = projectResource.Resource; }) .AddHttpMessageHandler(serviceProvider => { // build the token service that talk to the OAuth endpoint IOAuthClientFactory oauthClientFactory = serviceProvider.GetRequiredService <IOAuthClientFactory>(); IOAuthClient client = oauthClientFactory.Create(project); ITokenCache <OAuthOptions, Token> tokenCache = serviceProvider.GetRequiredService <ITokenCache <OAuthOptions, Token> >(); ITokenService tokenService = new OAuthTokenService(client, tokenCache); var handler = new TokenAuthorizationHandler(tokenService, CreateOAuthOptions(projectResource)); return(handler); }); var apiGatewayHost = projectResource.ApiGatewayHost; var apiGatewayPolicy = projectResource.ApiGatewayPolicy; if (!string.IsNullOrEmpty(apiGatewayHost) && !string.IsNullOrEmpty(apiGatewayPolicy)) { // add the ApiGatewayHandler logger.Information("Using {@ApiGateway} for {Resource}", new { Host = apiGatewayHost, Policy = apiGatewayPolicy }, projectResource.Resource); builder.AddHttpMessageHandler(() => new ApiGatewayHandler(apiGatewayHost, apiGatewayPolicy)); } }
public OAuthFlowsFactory(IOAuthClientFactory oAuthClientFactory) { _oAuthClientFactory = oAuthClientFactory; }
protected AccessTokenHealthCheckBase(ISamlAuthenticator samlAuthenticator, IOAuthClientFactory oauthClientFactory) { _samlAuthenticator = samlAuthenticator ?? throw new ArgumentNullException(nameof(samlAuthenticator)); _oauthClientFactory = oauthClientFactory ?? throw new ArgumentNullException(nameof(oauthClientFactory)); }
public ProjectAccessTokenHealthCheck(ProjectConfiguration project, ISamlAuthenticator samlAuthenticator, IOAuthClientFactory oauthClientFactory) : base(samlAuthenticator, oauthClientFactory) { _project = project ?? throw new ArgumentNullException(nameof(project)); }