Beispiel #1
0
        // 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();
        }
        public void CreateToken_GivenInvalidUsernamePassword_ShouldReturnTrueAndTokenWithSuccessMessage()
        {
            var logService = NSubstitute.Substitute.For <ILogService>();
            var cache      = NSubstitute.Substitute.For <IMemoryCache>();
            var setting    = NSubstitute.Substitute.For <IApplicationSetting>();
            var repository = new Auth0Repository(logService, cache, setting);
            var result     = repository.CreateToken("leeroya", "@nathan001");

            Assert.IsFalse(result.Condition);
        }
        public void CreateToken_GivenEmptyPassword_ShouldReturnFalseAndMessage()
        {
            var logService = NSubstitute.Substitute.For <ILogService>();
            var cache      = NSubstitute.Substitute.For <IMemoryCache>();
            var setting    = NSubstitute.Substitute.For <IApplicationSetting>();
            var repository = new Auth0Repository(logService, cache, setting);
            var result     = repository.CreateToken(string.Empty, "password");

            Assert.IsFalse(result.Condition);
            Assert.AreSame(result.Message, this._validationMessage);
        }
Beispiel #4
0
 public UserManagementController(ILogger <UserManagementController> logger, Auth0Repository auth0Repository)
 {
     _logger          = logger;
     _auth0Repository = auth0Repository;
 }