// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add Stormpath services var stormpathConfiguration = new StormpathConfiguration() { Web = new WebConfiguration() { ServerUri = "http://localhost:8080", Login = new WebLoginRouteConfiguration() //{ // View = "~/Views/Stormpath/MyLogin.cshtml" //} } }; services.AddStormpath(stormpathConfiguration); // Configure authorization policies here, which can include Stormpath requirements. services.AddAuthorization(opt => { opt.AddPolicy("CustomDataIT", policy => policy.AddRequirements(new StormpathCustomDataRequirement("testing", "rocks!"))); opt.AddPolicy("AdminITGroup", policy => policy.AddRequirements(new StormpathGroupsRequirement("adminIT"))); }); // Add framework services. services.AddMvc(); }
/// <summary> /// Adds services required for Stormpath. /// </summary> /// <param name="services">The <see cref="IServiceCollection" />.</param> /// <param name="configuration">Configuration for the Stormpath middleware.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <exception cref="Stormpath.Owin.InitializationException">There was a problem initializing Stormpath.</exception> public static IServiceCollection AddStormpath( this IServiceCollection services, StormpathConfiguration configuration) { return AddStormpath(services, new StormpathOwinOptions { Configuration = configuration }); }
public void Supplied_by_mutable_instance() { var stormpathConfiguration = new StormpathConfiguration() { Client = new ClientConfiguration() { ApiKey = new ClientApiKeyConfiguration() { File = null, Id = "modified-foobar", Secret = "modified-barbaz" }, CacheManager = new ClientCacheManagerConfiguration() { Enabled = false, DefaultTtl = 500, DefaultTti = 600, Caches = new Dictionary<string, ClientCacheConfiguration>() { ["application"] = new ClientCacheConfiguration() { Ttl = 450, Tti = 700 }, ["directory"] = new ClientCacheConfiguration() { Ttl = 200, Tti = 300 }, } }, BaseUrl = "https://api.foo.com/v1", ConnectionTimeout = 90, AuthenticationScheme = ClientAuthenticationScheme.Basic, Proxy = new ClientProxyConfiguration() { Port = 8088, Host = "proxy.foo.bar", Username = "******", Password = "******" } }, Application = new ApplicationConfiguration() { Name = "Lightsabers Galore", Href = "https://api.foo.com/v1/applications/foo" }, Web = new WebConfiguration() { ServerUri = "https://localhost:9000", BasePath = "#/", Oauth2 = new WebOauth2RouteConfiguration() { Enabled = false, Uri = "/oauth2/token", Client_Credentials = new WebOauth2ClientCredentialsGrantConfiguration() { Enabled = false, AccessToken = new WebOauth2TokenConfiguration() { Ttl = 3601 } }, Password = new WebOauth2PasswordGrantConfiguration() { Enabled = false, ValidationStrategy = WebOauth2TokenValidationStrategy.Stormpath } }, AccessTokenCookie = new WebCookieConfiguration() { Name = "accessToken", HttpOnly = false, Secure = false, Path = "/bar", Domain = "foo.bar" }, RefreshTokenCookie = new WebCookieConfiguration() { Name = "refreshToken", HttpOnly = false, Secure = true, Path = "/foo", Domain = "baz.qux" }, Produces = new List<string>() { "foo/bar" }, Register = new WebRegisterRouteConfiguration() { Enabled = false, Uri = "/register1", NextUri = "/1", AutoLogin = true, View = "registerView", Form = new WebRegisterRouteFormConfiguration() { Fields = new Dictionary<string, WebFieldConfiguration>() { ["email"] = new WebFieldConfiguration() { Enabled = false, Visible = false, Label = "I Can Has Email", Placeholder = "Can Has?", Required = false, Type = "text" } }, FieldOrder = new List<string>() { "email", "hidden" } } }, VerifyEmail = new WebVerifyEmailRouteConfiguration() { Enabled = true, Uri = "/verify1", NextUri = "/login2", View = "verifyView" }, Login = new WebLoginRouteConfiguration() { Enabled = false, Uri = "/login3", NextUri = "/3", View = "loginView", Form = new WebLoginRouteFormConfiguration() { Fields = new Dictionary<string, WebFieldConfiguration>() { ["password"] = new WebFieldConfiguration() { Enabled = false, Visible = false, Label = "Password?", Placeholder = "Maybe", Required = false, Type = "email" } }, FieldOrder = new List<string>() { "password" } } }, Logout = new WebLogoutRouteConfiguration() { Enabled = false, Uri = "/logout4", NextUri = "/4" }, ForgotPassword = new WebForgotPasswordRouteConfiguration() { Enabled = true, Uri = "/forgot5", View = "forgot-password-view", NextUri = "/login?status=forgot!" }, ChangePassword = new WebChangePasswordRouteConfiguration() { Enabled = true, Uri = "/change6", NextUri = "/login?status=reset?", View = "change-password-view", ErrorUri = "/forgot?status=invalid_sptoken:(" }, IdSite = new WebIdSiteConfiguration() { Enabled = true, LoginUri = "/456", ForgotUri = "/#/forgot789", RegisterUri = "/#/register0" }, Callback = new WebCallbackRouteConfiguration() { Enabled = false, Uri = "/stormpath-callback" }, Social = new Dictionary<string, WebSocialProviderConfiguration>() { ["facebook"] = new WebSocialProviderConfiguration() { Uri = "/callbackz/facebook", Scope = "email birthday" }, ["github"] = new WebSocialProviderConfiguration() { Uri = "/callbackz/github", Scope = "user:everything" }, ["google"] = new WebSocialProviderConfiguration() { Uri = "/callbackz/google", Scope = "email profile friends" }, ["linkedin"] = new WebSocialProviderConfiguration() { Uri = "/callbackz/linkedin", Scope = "email interests" } }, Me = new WebMeRouteConfiguration() { Enabled = false, Uri = "/myself", Expand = new Dictionary<string, bool>() { ["directory"] = true } } } }; var config = ConfigurationLoader.Initialize().Load(stormpathConfiguration); ValidateConfig(config); }
public void Mutable_config_initialization_works() { var test = new StormpathConfiguration { Client = new ClientConfiguration { ApiKey = new ClientApiKeyConfiguration { Id = "testing-foobar", Secret = "testing-foobar" } }, Application = new ApplicationConfiguration { Name = "My Application!" }, Web = new WebConfiguration { Login = new WebLoginRouteConfiguration { View = "test" } } }; var config = ConfigurationLoader.Initialize().Load(test); config.Application.Name.Should().Be("My Application!"); config.Web.Login.View.Should().Be("test"); }