public async void UseCloudFoundryAuthentication_UsesOAuthServiceOptionsIfPresent() { // Arrange OAuthServiceOptions serviceOptions = new OAuthServiceOptions() { ClientId = "ClientId", ClientSecret = "ClientSecret", UserAuthorizationUrl = "http://userauthorizationurl/oauth/authorize", AccessTokenUrl = "http://AccessTokenUrl", UserInfoUrl = "http://UserInfoUrl", TokenInfoUrl = "http://TokenInfoUrl", JwtKeyUrl = "http://JwtKeyUrl", Scope = { "foo", "bar" } }; IHostingEnvironment envir = new HostingEnvironment(); TestServerStartup.CloudFoundryOptions = null; TestServerStartup.ServiceOptions = serviceOptions; var builder = new WebHostBuilder().UseStartup <TestServerStartup>().UseEnvironment("development"); using (var server = new TestServer(builder)) { var client = server.CreateClient(); var result = await client.GetAsync("http://localhost/"); Assert.Equal(HttpStatusCode.Redirect, result.StatusCode); var location = result.Headers.Location.ToString(); Assert.True(location.StartsWith("http://userauthorizationurl/oauth/authorize")); } }
public void OAuthServiceOptionsConstructor_SetsupOptionsAsExpected() { OAuthServiceOptions oauthOpts = new OAuthServiceOptions() { ClientId = "ClientId", ClientSecret = "ClientSecret", UserAuthorizationUrl = "UserAuthorizationUrl", AccessTokenUrl = "AccessTokenUrl", UserInfoUrl = "UserInfoUrl", TokenInfoUrl = "TokenInfoUrl", JwtKeyUrl = "JwtKeyUrl", Scope = { "foo", "bar" } }; CloudFoundryOptions opts = new CloudFoundryOptions(oauthOpts); Assert.Equal(CloudFoundryOptions.AUTHENTICATION_SCHEME, opts.ClaimsIssuer); Assert.Equal("ClientId", opts.ClientId); Assert.Equal("ClientSecret", opts.ClientSecret); Assert.Equal(CloudFoundryOptions.OAUTH_AUTHENTICATION_SCHEME, opts.AuthenticationScheme); Assert.Equal(CloudFoundryOptions.AUTHENTICATION_SCHEME, opts.DisplayName); Assert.Equal(new PathString("/signin-cloudfoundry"), opts.CallbackPath); Assert.Equal("UserAuthorizationUrl", opts.AuthorizationEndpoint); Assert.Equal("AccessTokenUrl", opts.TokenEndpoint); Assert.Equal("UserInfoUrl", opts.UserInformationEndpoint); Assert.Equal("TokenInfoUrl", opts.TokenInfoUrl); Assert.Equal("JwtKeyUrl", opts.JwtKeyUrl); Assert.True(opts.Scope.Contains("foo")); Assert.True(opts.Scope.Contains("bar")); Assert.True(opts.ValidateCertificates); }
public void GetBackChannelHandler_ReturnsCorrectly() { CloudFoundryOptions opts = new CloudFoundryOptions(); Assert.Null(opts.GetBackChannelHandler()); opts = new CloudFoundryOptions() { ValidateCertificates = false }; #if NET452 Assert.Null(opts.GetBackChannelHandler()); #else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.NotNull(opts.GetBackChannelHandler()); } #endif OAuthServiceOptions oauthOpts = new OAuthServiceOptions() { ClientId = "ClientId", ClientSecret = "ClientSecret", UserAuthorizationUrl = "UserAuthorizationUrl", AccessTokenUrl = "AccessTokenUrl", UserInfoUrl = "UserInfoUrl", TokenInfoUrl = "TokenInfoUrl", JwtKeyUrl = "JwtKeyUrl", Scope = { "foo", "bar" } }; opts = new CloudFoundryOptions(oauthOpts); Assert.Null(opts.GetBackChannelHandler()); opts = new CloudFoundryOptions(oauthOpts) { ValidateCertificates = false }; #if NET452 Assert.Null(opts.GetBackChannelHandler()); #else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Assert.NotNull(opts.GetBackChannelHandler()); } #endif }
public CloudFoundryOptions(OAuthServiceOptions options) : this() { ClientId = options.ClientId; ClientSecret = options.ClientSecret; AuthorizationEndpoint = options.UserAuthorizationUrl; TokenEndpoint = options.AccessTokenUrl; UserInformationEndpoint = options.UserInfoUrl; TokenInfoUrl = options.TokenInfoUrl; JwtKeyUrl = options.JwtKeyUrl; AutomaticChallenge = true; foreach (var scope in options.Scope) { Scope.Add(scope); } BackchannelHttpHandler = GetBackChannelHandler(); }
public void Update_WithServiceInfo_UpdatesOAuthOptions_AsExpected() { var opts = new OAuthServiceOptions(); var si = new SsoServiceInfo("myId", "myClientId", "myClientSecret", "https://foo.bar"); var configurer = new OAuthConfigurer(); configurer.UpdateOptions(si, opts); Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); Assert.Equal("myClientId", opts.ClientId); Assert.Equal("myClientSecret", opts.ClientSecret); Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); Assert.Equal("https://foo.bar" + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); Assert.True(opts.ValidateCertificates); Assert.NotNull(opts.Scope); Assert.Equal(0, opts.Scope.Count); }
public void Update_WithDefaultConnectorOptions_UpdatesOAuthOptions_AsExpected() { var opts = new OAuthServiceOptions(); var config = new OAuthConnectorOptions() { ValidateCertificates = false }; var configurer = new OAuthConfigurer(); configurer.UpdateOptions(config, opts); Assert.Equal(OAuthConnectorDefaults.Default_OAuthServiceUrl + OAuthConnectorDefaults.Default_AccessTokenUri, opts.AccessTokenUrl); Assert.Equal(OAuthConnectorDefaults.Default_ClientId, opts.ClientId); Assert.Equal(OAuthConnectorDefaults.Default_ClientSecret, opts.ClientSecret); Assert.Equal(OAuthConnectorDefaults.Default_OAuthServiceUrl + OAuthConnectorDefaults.Default_JwtTokenKey, opts.JwtKeyUrl); Assert.Equal(OAuthConnectorDefaults.Default_OAuthServiceUrl + OAuthConnectorDefaults.Default_CheckTokenUri, opts.TokenInfoUrl); Assert.Equal(OAuthConnectorDefaults.Default_OAuthServiceUrl + OAuthConnectorDefaults.Default_AuthorizationUri, opts.UserAuthorizationUrl); Assert.Equal(OAuthConnectorDefaults.Default_OAuthServiceUrl + OAuthConnectorDefaults.Default_UserInfoUri, opts.UserInfoUrl); Assert.False(opts.ValidateCertificates); Assert.NotNull(opts.Scope); Assert.Equal(0, opts.Scope.Count); }
internal protected virtual void UpdateOptions(OAuthServiceOptions options) { if (options == null || options.ClientId == null || options.ClientId.Equals(OAuthConnectorDefaults.Default_ClientId)) { return; } ClientId = options.ClientId; ClientSecret = options.ClientSecret; AuthorizationEndpoint = options.UserAuthorizationUrl; TokenEndpoint = options.AccessTokenUrl; UserInformationEndpoint = options.UserInfoUrl; TokenInfoUrl = options.TokenInfoUrl; JwtKeyUrl = options.JwtKeyUrl; ValidateCertificates = options.ValidateCertificates; foreach (var scope in options.Scope) { Scope.Add(scope); } BackchannelHttpHandler = GetBackChannelHandler(); }
public HomeController(IOptions <OAuthServiceOptions> oauthOptions) { _options = oauthOptions.Value; }