// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // rbrands: Add authentication with Auth0 services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = Configuration["Auth0:Authority"]; options.Audience = Configuration["Auth0:ApiIdentifier"]; }); // rbrands: Add policies services.AddAuthorization(options => options.AddAppPolicies(Configuration["Auth0:Authority"])); // rbrands: register the scope authorization handler services.AddSingleton <IAuthorizationHandler, BlazorAuth0Demo.Shared.HasScopeHandler>(); // rbrands: Initialize Auth0Repository services.Configure <Auth0Config>(Configuration.GetSection("Auth0Management")); Auth0Config auth0ManagementConfig = Configuration.GetSection("Auth0Management").Get <Auth0Config>(); Auth0Repository auth0Repository = new Auth0Repository(auth0ManagementConfig); services.AddSingleton(auth0Repository); services.AddControllersWithViews(); services.AddRazorPages(); services.AddHttpContextAccessor(); }
// ReSharper disable once UnusedMember.Global public void ConfigureServices(IServiceCollection services) { services.AddMemoryCache(); services.AddTransient <IBlogRepository, FileBlogRepository>(); services.AddTransient <IPageRepository, JsonPageRepository>(); services.AddTransient <IPostRepository, JsonPostRepository>(); services.AddScoped <IApplicationContext, ApplicationContext>(); services.Configure <XmlRpcSecurityOptions>(Configuration.GetSection("XmlRpcSecurity")); Auth0Config.ConfigureServices(services, Configuration); services.AddMvc() .AddRazorRuntimeCompilation(); services.Configure <RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new ThemeViewLocationExpander()); }); services.AddAuthorization(options => { options.AddPolicy("RequireAdminRole", policy => policy.RequireRole("admin")); }); }
protected void InitializeAuth0Client() { this.auth0Config = this.configurationRepository.GetConfiguration(); if (!this.auth0Config.IsValid) { return; } try { var clientsIds = this.auth0Config.ClientId.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var clientsSecrets = this.auth0Config.ClientSecret.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); var clientIdIndex = Array.IndexOf(clientsIds, Utils.GetClaimsValue(ClientIdClaimsType)); // if clientID was not found, use the first one configured on central admin if (clientIdIndex == -1) { clientIdIndex = 0; } this.auth0Client = new Auth0.Client( clientsIds[clientIdIndex], clientsSecrets[clientIdIndex], this.auth0Config.Domain); } catch (Exception ex) { Auth0LoggingService.WriteError(ex.ToString()); } this.alwaysResolveValue = true; //this.auth0Config.AlwaysResolveUserInput; this.pickerEntityGroupName = this.auth0Config.PickerEntityGroupName; }
public CompareApiController( IClaimService claimService, ViewRender view, IOptions <Auth0Config> config, IHostingEnvironment env, IOptions <AsposeOptions> asposeOptions) { _claimService = claimService; _view = view; _auth0Config = config.Value; _env = env; _asposeOptions = asposeOptions.Value; }
public ValidateConfigFile(DatabaseConfigValidator databaseConfigValidator, DatabaseConfig databaseConfig, Auth0ConfigValidator auth0ConfigValidator, Auth0Config auth0Config, EmailConfigValidator emailConfigValidat, EmailConfig emailConfig, AdminConfigValidator adminConfigValidator, AdminConfig adminConfig, BillingConfigValidator configValidator, IBillingConfig config) { this.databaseConfigValidator = databaseConfigValidator; this.databaseConfig = databaseConfig; this.auth0ConfigValidator = auth0ConfigValidator; this.auth0Config = auth0Config; this.emailConfigValidator = emailConfigValidat; this.emailConfig = emailConfig; this.adminConfigValidator = adminConfigValidator; this.adminConfig = adminConfig; this.billingConfigValidator = configValidator; this.billingConfig = config; }
public ClaimApiController( IClaimService claimService, IPostcodeService postcodeService, IOptions <Auth0Config> config, IOptions <AsposeOptions> asposeOptions, IHostingEnvironment env, ViewRender view) { _claimService = claimService; _postcodeService = postcodeService; _view = view; _auth0Config = config.Value; _asposeOptions = asposeOptions.Value; _env = env; }
public UsersRepository( InstaPostContext context, IOptions <Auth0Config> authConfig, IOptions <CloudinaryConfig> cloudinaryConfig ) { this.db = context; this.authConfig = authConfig.Value; CloudinaryConfig cloudConfig = cloudinaryConfig.Value; Account account = new Account( cloudConfig.CloudName, cloudConfig.Key, cloudConfig.Secret ); Cloudinary cloudinary = new Cloudinary(account); this.imgCloud = cloudinary; }
private void PopulateFields() { Auth0Config auth0Config = null; SPSecurity.RunWithElevatedPrivileges(delegate { // Get SPPersisted Object this.Web.AllowUnsafeUpdates = true; auth0Config = this.configurationRepository.GetConfiguration(); this.Web.AllowUnsafeUpdates = false; }); if (auth0Config != null) { this.DomainTextBox.Text = auth0Config.Domain; this.ClientIdTextBox.Text = auth0Config.ClientId; this.ClientSecretTextBox.Text = auth0Config.ClientSecret; this.IdentifierUserFieldTextBox.Text = auth0Config.IdentifierUserField; this.PickerEntityGroupNameTextBox.Text = auth0Config.PickerEntityGroupName; } }
public static IServiceCollection AddConceptsAuthentication(this IServiceCollection services, IConfiguration config) { var auth0Config = new Auth0Config(); config.GetSection(ConfigSections.Auth0).Bind(auth0Config); var scopes = new List <string> { auth0Config.Scope.ConceptAdmin, auth0Config.Scope.ConceptWrite, }; services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.Authority = auth0Config.DomainUrl; options.Audience = auth0Config.Audience; }); services.AddAuthorization(options => { foreach (var scope in scopes) { options.AddPolicy(scope, policy => policy.Requirements.Add(new HasScopeRequirement(scope, auth0Config.DomainUrl))); } }); // register the scope authorization handler services.AddSingleton <IAuthorizationHandler, HasScopeHandler>(); return(services); }
public TokenHelper(IOptions <Auth0Config> config, IHttpContextAccessor ca) { _auth0Config = config.Value; _httpContextAccessor = ca; }
public Auth0ApiClientBuilder(Auth0Config config) { this.config = config; }
protected void InitializeApiClient(Uri context) { // Already initialized. if (this.client != null && this.clientContext == context) { return; } // Invalid. this.configuration = this.configurationRepository.GetConfiguration(); if (!this.configuration.IsValid) { logger.ConfigurationInvalid(); return; } try { // Split multiple values if any. var domains = this.configuration.Domain.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); var clientsIds = this.configuration.ClientId.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); var clientsSecrets = this.configuration.ClientSecret.Split(new string[] { Environment.NewLine, ";", "," }, StringSplitOptions.None); // Try to find the current client. var clientIdIndex = Array.IndexOf(clientsIds, Utils.GetClaimsValue(DefaultClaimTypes.ClientId)); if (clientIdIndex == -1) { var webApplicationClientId = GetWebApplicationClientId(context); if (webApplicationClientId != null) { clientIdIndex = Array.IndexOf(clientsIds, webApplicationClientId); } logger.ClientIdFound(context, webApplicationClientId); if (clientIdIndex == -1) { throw new InvalidOperationException("Unable to find client ID for: " + context.ToString()); } } // Get values. var clientId = clientsIds[clientIdIndex]; var domain = domains[clientIdIndex]; // Initialize client. this.client = new Auth0.Client( clientId, clientsSecrets[clientIdIndex], domain, diagnostics: DiagnosticsHeader.Default .AddEnvironment("SharePoint", "2013") .AddEnvironment("ClaimsProvider", GetType().Assembly.FullName)); this.clientContext = context; // Log complete. logger.ConfigurationInitialized(context, domain, clientId); } catch (Exception ex) { logger.ConfigurationError(ex); throw; } this.alwaysResolveValue = true; //this.auth0Config.AlwaysResolveUserInput; this.pickerEntityGroupName = this.configuration.PickerEntityGroupName; }
public Auth0UserGateway(Auth0Config config, IAuth0ApiClientBuilder tokenGenerator) { Config = config; this.tokenGenerator = tokenGenerator; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <NswagOptions>(Configuration.GetSection("NSwag")); var auth0ConfigSection = Configuration.GetSection("Auth0"); services.Configure <Auth0Config>(auth0ConfigSection); services.AddDbContext <SplitThatBillContext>(options => { options.UseMySql(Configuration.GetConnectionString("SplitThatBillDb"), config => config.MigrationsAssembly("SplitThatBill.Backend.Data")); }); services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .WithExposedHeaders(new[] { "Location" }); }); options.AddPolicy("OnlyIdentifiedOrigin", builder => { builder .WithOrigins(Configuration.GetValue <string>("CORSOrigin")) .AllowAnyHeader() .AllowAnyMethod() .WithExposedHeaders(new[] { "Location" }); }); }); services.AddRouting(opts => opts.LowercaseUrls = true); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { var auth0Config = new Auth0Config(); auth0ConfigSection.Bind(auth0Config); options.Authority = $"https://{auth0Config.Domain}/"; options.Audience = auth0Config.Audience; options.TokenValidationParameters = new TokenValidationParameters { NameClaimType = ClaimTypes.NameIdentifier }; options.Events = new JwtBearerEvents { OnTokenValidated = context => { if (context.SecurityToken is JwtSecurityToken token) { if (context.Principal.Identity is ClaimsIdentity identity) { identity.AddClaim(new Claim("access_token", token.RawData)); } } return(Task.FromResult(0)); } }; }); var businessAssembly = Assembly.Load("SplitThatBill.Backend.Business"); services .AddControllers(options => { options.EnableEndpointRouting = false; }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0) .AddNewtonsoftJson(options => { // Use camel case properties in the serializer and the spec (optional) options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Use string enums in the serializer and the spec (optional) options.SerializerSettings.Converters.Add(new StringEnumConverter()); }) .AddFluentValidation(fv => { fv.RegisterValidatorsFromAssembly(businessAssembly); fv.RunDefaultMvcValidationAfterFluentValidationExecutes = false; fv.ImplicitlyValidateChildProperties = true; }); services.AddOpenApiDocument((config, sp) => { var nswagOptions = sp.GetRequiredService <IOptionsMonitor <NswagOptions> >().CurrentValue; config.PostProcess = document => { document.Info.Version = nswagOptions.Info.Version; document.Info.Title = nswagOptions.Info.Title; document.Info.Description = nswagOptions.Info.Description; document.Info.TermsOfService = nswagOptions.Info.TermsOfService; document.Info.Contact = new NSwag.OpenApiContact { Name = nswagOptions.Info.Contact.Name, Email = nswagOptions.Info.Contact.Email, Url = nswagOptions.Info.Contact.Url }; }; }); services.AddScoped <IContextData, RequestContextData>(); services.AddMediatR(businessAssembly); services.AddAutoMapper(businessAssembly); services.AddTransient <IDateTimeManager, DateTimeManager>(); services.AddTransient <IExternalIdGenerator, GuidExternalIdGenerator>(); }