1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-29 18:07:36 +01:00

deprec. api identity, set base uris from settings

This commit is contained in:
Kyle Spearrin 2017-08-02 16:57:32 -04:00
parent a71f2198e9
commit 897c354577
12 changed files with 27 additions and 29 deletions

View File

@ -66,9 +66,6 @@ namespace Bit.Api
services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>();
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
// IdentityServer
services.AddCustomIdentityServerServices(Environment, globalSettings);
// Identity // Identity
services.AddCustomIdentityServices(globalSettings); services.AddCustomIdentityServices(globalSettings);
@ -166,11 +163,8 @@ namespace Bit.Api
app.UseCors("All"); app.UseCors("All");
// Add IdentityServer to the request pipeline. // Add IdentityServer to the request pipeline.
app.UseIdentityServer(); app.UseIdentityServerAuthentication(GetIdentityOptions(env, globalSettings, string.Empty));
app.UseIdentityServerAuthentication( app.UseIdentityServerAuthentication(GetIdentityOptions(env, globalSettings, "3"));
GetIdentityOptions(env, IdentityServerAuthority(env, "identity", "33656"), "3"));
app.UseIdentityServerAuthentication(
GetIdentityOptions(env, IdentityServerAuthority(env, "api", "4000"), "2"));
// Add current context // Add current context
app.UseMiddleware<CurrentContextMiddleware>(); app.UseMiddleware<CurrentContextMiddleware>();
@ -180,39 +174,21 @@ namespace Bit.Api
} }
private IdentityServerAuthenticationOptions GetIdentityOptions(IHostingEnvironment env, private IdentityServerAuthenticationOptions GetIdentityOptions(IHostingEnvironment env,
string authority, string suffix) GlobalSettings globalSettings, string suffix)
{ {
var options = new IdentityServerAuthenticationOptions var options = new IdentityServerAuthenticationOptions
{ {
Authority = authority, Authority = globalSettings.BaseIdentityUri,
AllowedScopes = new string[] { "api" }, AllowedScopes = new string[] { "api" },
RequireHttpsMetadata = !env.IsDevelopment(), RequireHttpsMetadata = !env.IsDevelopment(),
ApiName = "api", ApiName = "api",
NameClaimType = ClaimTypes.Email, NameClaimType = ClaimTypes.Email,
// Suffix until we retire the old jwt schemes. // Suffix until we retire the old jwt schemes.
AuthenticationScheme = $"Bearer{suffix}", AuthenticationScheme = $"Bearer{suffix}",
TokenRetriever = TokenRetrieval.FromAuthorizationHeaderOrQueryString( TokenRetriever = TokenRetrieval.FromAuthorizationHeaderOrQueryString($"Bearer{suffix}", $"access_token{suffix}")
$"Bearer{suffix}", $"access_token{suffix}")
}; };
return options; return options;
} }
private string IdentityServerAuthority(IHostingEnvironment env, string subdomain, string port)
{
if(env.IsProduction())
{
return $"https://{subdomain}.bitwarden.com";
}
else if(env.IsEnvironment("Preview"))
{
return $"https://preview-{subdomain}.bitwarden.com";
}
else
{
return $"http://localhost:{port}";
//return $"http://192.168.1.3:{port}"; // Desktop external
}
}
} }
} }

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://preview-vault.bitwarden.com/#", "baseVaultUri": "https://preview-vault.bitwarden.com/#",
"baseApiUri": "https://preview-api.bitwarden.com",
"baseIdentityUri": "https://preview-identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://preview-vault.bitwarden.com/app-id.json" "appId": "https://preview-vault.bitwarden.com/app-id.json"
} }

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://vault.bitwarden.com/#", "baseVaultUri": "https://vault.bitwarden.com/#",
"baseApiUri": "https://api.bitwarden.com",
"baseIdentityUri": "https://identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://vault.bitwarden.com/app-id.json" "appId": "https://vault.bitwarden.com/app-id.json"
}, },

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://vault.bitwarden.com/#", "baseVaultUri": "https://vault.bitwarden.com/#",
"baseApiUri": "https://api.bitwarden.com",
"baseIdentityUri": "https://identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://vault.bitwarden.com/app-id.json" "appId": "https://vault.bitwarden.com/app-id.json"
} }

View File

@ -2,6 +2,8 @@
"globalSettings": { "globalSettings": {
"siteName": "bitwarden", "siteName": "bitwarden",
"baseVaultUri": "http://localhost:4001/#", "baseVaultUri": "http://localhost:4001/#",
"baseApiUri": "http://localhost:4000",
"baseIdentityUri": "http://localhost:33656",
"stripeApiKey": "SECRET", "stripeApiKey": "SECRET",
"sqlServer": { "sqlServer": {
"connectionString": "SECRET" "connectionString": "SECRET"

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://vault.bitwarden.com/#", "baseVaultUri": "https://vault.bitwarden.com/#",
"baseApiUri": "https://api.bitwarden.com",
"baseIdentityUri": "https://identity.bitwarden.com",
"braintree": { "braintree": {
"production": true "production": true
} }

View File

@ -2,6 +2,8 @@
"globalSettings": { "globalSettings": {
"siteName": "bitwarden", "siteName": "bitwarden",
"baseVaultUri": "http://localhost:4001/#", "baseVaultUri": "http://localhost:4001/#",
"baseApiUri": "http://localhost:4000",
"baseIdentityUri": "http://localhost:33656",
"stripeApiKey": "SECRET", "stripeApiKey": "SECRET",
"sqlServer": { "sqlServer": {
"connectionString": "SECRET" "connectionString": "SECRET"

View File

@ -4,6 +4,8 @@
{ {
public virtual string SiteName { get; set; } public virtual string SiteName { get; set; }
public virtual string BaseVaultUri { get; set; } public virtual string BaseVaultUri { get; set; }
public virtual string BaseApiUri { get; set; }
public virtual string BaseIdentityUri { get; set; }
public virtual string StripeApiKey { get; set; } public virtual string StripeApiKey { get; set; }
public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings(); public virtual SqlServerSettings SqlServer { get; set; } = new SqlServerSettings();
public virtual MailSettings Mail { get; set; } = new MailSettings(); public virtual MailSettings Mail { get; set; } = new MailSettings();

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://preview-vault.bitwarden.com/#", "baseVaultUri": "https://preview-vault.bitwarden.com/#",
"baseApiUri": "https://preview-api.bitwarden.com",
"baseIdentityUri": "https://preview-identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://preview-vault.bitwarden.com/app-id.json" "appId": "https://preview-vault.bitwarden.com/app-id.json"
} }

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://vault.bitwarden.com/#", "baseVaultUri": "https://vault.bitwarden.com/#",
"baseApiUri": "https://api.bitwarden.com",
"baseIdentityUri": "https://identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://vault.bitwarden.com/app-id.json" "appId": "https://vault.bitwarden.com/app-id.json"
}, },

View File

@ -1,6 +1,8 @@
{ {
"globalSettings": { "globalSettings": {
"baseVaultUri": "https://vault.bitwarden.com/#", "baseVaultUri": "https://vault.bitwarden.com/#",
"baseApiUri": "https://api.bitwarden.com",
"baseIdentityUri": "https://identity.bitwarden.com",
"u2f": { "u2f": {
"appId": "https://vault.bitwarden.com/app-id.json" "appId": "https://vault.bitwarden.com/app-id.json"
} }

View File

@ -2,6 +2,8 @@
"globalSettings": { "globalSettings": {
"siteName": "bitwarden", "siteName": "bitwarden",
"baseVaultUri": "http://localhost:4001/#", "baseVaultUri": "http://localhost:4001/#",
"baseApiUri": "http://localhost:4000",
"baseIdentityUri": "http://localhost:33656",
"stripeApiKey": "SECRET", "stripeApiKey": "SECRET",
"sqlServer": { "sqlServer": {
"connectionString": "SECRET" "connectionString": "SECRET"