private static IInternalClient GetApi(CommandLineConfig config) { if (config.MomentumApiBaseUri == null) { throw new System.Exception("You must specify a MomentumApiBaseUri"); } var tokenProviderOptions = new LogicTokenProviderOptions { AuthorizationScope = config.TokenProvider.AuthorizationScope, ClientId = config.TokenProvider.ClientId, ClientSecret = config.TokenProvider.ClientSecret, AuthorizationTokenIssuer = config.TokenProvider.AuthorizationTokenIssuer, }; if (config.TokenProvider.AuthorizationTokenIssuer != null) { tokenProviderOptions.AuthorizationTokenIssuer = config.TokenProvider.AuthorizationTokenIssuer; } var httpClient = new HttpClient(); var tokenProviderFactory = new LogicTokenProviderFactory(tokenProviderOptions); var tokenProvider = tokenProviderFactory.GetProvider(httpClient); var client = new InternalClient(new TokenCredentials(tokenProvider)) { BaseUri = config.MomentumApiBaseUri, }; Log.Information("Created API with Base URI {BaseUri}", client.BaseUri); return(client); }
private static async Task Run(AppSettings configuration) { var validator = new ConfigurationValidator(configuration); if (!validator.Validate()) { return; } var options = new LogicTokenProviderOptions { ClientId = configuration.ClientId, ClientSecret = configuration.ClientSecret, Tenant = configuration.Tenant, }; if (!string.IsNullOrEmpty(configuration.AuthorizationScope)) { options.AuthorizationScope = configuration.AuthorizationScope; } if (configuration.AuthorizationTokenIssuer != null) { options.AuthorizationTokenIssuer = configuration.AuthorizationTokenIssuer; } using (var tokenFactory = new LogicTokenProviderFactory(options)) using (var httpClient = new HttpClient()) { var provider = tokenFactory.GetProvider(httpClient); Log.Information("Requesting access to scope {Scope} with client id {ClientId}", options.AuthorizationScope, options.ClientId); var authHeader = await provider.GetAuthenticationHeaderAsync(CancellationToken.None).ConfigureAwait(false); Log.Information("Retrieved authorization header {Scheme} {Parameter}", authHeader.Scheme, authHeader.Parameter); var jwt = new JsonWebToken(authHeader.Parameter); Log.Information("Deserialized JWT {@Jwt}", jwt); } }