/// <summary> /// Read configuration from file. /// </summary> protected virtual void LoadConfig() { var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); if (assemblyPath == null) { throw new DirectoryNotFoundException("The assembly path could not be resolved."); } var configLocation = Path.Combine(assemblyPath, this.Configpath); if (!File.Exists(configLocation)) { throw new FileNotFoundException("Configuration file not found.", configLocation); } var json = File.ReadAllText(configLocation); if (string.IsNullOrWhiteSpace(json)) { throw new ConfigurationErrorsException("Configuration file is empty.", configLocation, 0); } this.AuthenticatorConfig = this.DeserializeConfigFile(json, configLocation); }
static ICredentials GetCredentials(ISecretsProvider secrets) { var apiKey = secrets.GetNamedSecret(ApiKeyEnvironmentVariable).TrimToNull(); var tokenUrl = secrets.GetNamedSecret(TokenUrlEnvironmentVariable).TrimToNull(); var clientId = secrets.GetNamedSecret(ClientIdEnvironmentVariable).TrimToNull(); var clientSecret = secrets.GetNamedSecret(ClientSecretEnvironmentVariable).TrimToNull(); var tokenScopes = secrets.GetNamedSecret(TokenScopesEnvironmentVariable).TrimToNull(); var tokenAudience = secrets.GetNamedSecret(TokenAudienceEnvironmentVariable).TrimToNull(); var project = secrets.GetNamedSecret(ProjectEnvironmentVariable).TrimToNull(); if (apiKey != null) { return(new ApiKeyCredentials(apiKey)); } else if (tokenUrl != null && clientId != null && clientSecret != null && project != null) { var scopeList = new List <string>(); if (tokenScopes != null && tokenScopes != "") { scopeList = new List <string>(tokenScopes.Split(",")); } var authConfig = new AuthenticatorConfig { Implementation = AuthenticatorConfig.AuthenticatorImplementation.Basic, ClientId = clientId, Secret = clientSecret, TokenUrl = tokenUrl, Scopes = scopeList, Audience = tokenAudience }; return(new TokenCredentials(authConfig, project)); } else { throw new JetfireCliException($"Either the {ApiKeyEnvironmentVariable} environment variable, or the {TokenUrlEnvironmentVariable}, {ClientIdEnvironmentVariable}, {ClientSecretEnvironmentVariable}, {TokenScopesEnvironmentVariable} and {ProjectEnvironmentVariable} environment variables must be set"); } }
public async Task <bool> UpdateAuthenticationExecutionConfigurationAsync(string realm, string executionId, AuthenticatorConfig authenticatorConfig) { var response = await GetBaseUrl(realm) .AppendPathSegment($"/admin/realms/{realm}/authentication/executions/{executionId}/config") .PostJsonAsync(authenticatorConfig) .ConfigureAwait(false); return(response.IsSuccessStatusCode); }
public TokenCredentials(AuthenticatorConfig authenticatorConfig, string project) { Authenticator = new Authenticator(authenticatorConfig, new HttpClient(), NullLogger <IAuthenticator> .Instance); Project = project; }