Skip to content

Commit 45deaf1

Browse files
authored
Merge pull request #380 from serverlessworkflow/fix-oidc-discovery
Fixed the OAuth2TokenManager by disabling HTTPS requirements when performing OIDC discovery requests
2 parents 69dc8c1 + 6176494 commit 45deaf1

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

deployments/docker-compose/docker-compose.build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
CONNECTIONSTRINGS__REDIS: ${GARNET_URI}
1414
SYNAPSE_DASHBOARD_SERVE: true
1515
SYNAPSE_API_AUTH_TOKEN_FILE: /app/tokens.yaml
16+
SYNAPSE_API_JWT_AUTHORITY: http://api:8080
1617
volumes:
1718
- ./config/tokens.yaml:/app/tokens.yaml
1819
ports:

deployments/docker-compose/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
CONNECTIONSTRINGS__REDIS: ${GARNET_URI}
1212
SYNAPSE_DASHBOARD_SERVE: true
1313
SYNAPSE_API_AUTH_TOKEN_FILE: /app/tokens.yaml
14-
SYNAPSE_API_AUTH_AUTHORITY: http://api:8080
14+
SYNAPSE_API_JWT_AUTHORITY: http://api:8080
1515
volumes:
1616
- ./config/tokens.yaml:/app/tokens.yaml
1717
ports:

src/api/Synapse.Api.Server/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var applicationOptions = new ApiServerOptions();
1919
builder.Configuration.Bind(applicationOptions);
2020
if (applicationOptions.Authentication.Tokens.Count < 1) throw new Exception("The Synapse API server requires that at least one static user token be configured");
21-
var authority = builder.Environment.RunsInDocker() || builder.Environment.RunsInKubernetes() ? Environment.GetEnvironmentVariable("SYNAPSE_API_AUTH_AUTHORITY") : null;
21+
var authority = builder.Environment.RunsInDocker() || builder.Environment.RunsInKubernetes() ? Environment.GetEnvironmentVariable("SYNAPSE_API_JWT_AUTHORITY") : null;
2222

2323
builder.Services.Configure<ApiServerOptions>(builder.Configuration);
2424
builder.Services.AddResponseCompression();

src/core/Synapse.Core.Infrastructure/Services/OAuth2TokenManager.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ public virtual async Task<OAuth2Token> GetTokenAsync(OAuth2AuthenticationSchemeD
6464
Uri tokenEndpoint;
6565
if (configuration is OpenIDConnectSchemeDefinition)
6666
{
67-
var discoveryDocument = await this.HttpClient.GetDiscoveryDocumentAsync(configuration.Authority.OriginalString, cancellationToken).ConfigureAwait(false);
68-
if (string.IsNullOrWhiteSpace(discoveryDocument.TokenEndpoint)) throw new NullReferenceException("The token endpoint is not documented by the OIDC discovery document");
67+
var discoveryRequest = new DiscoveryDocumentRequest()
68+
{
69+
Address = configuration.Authority.OriginalString,
70+
Policy = new()
71+
{
72+
RequireHttps = false
73+
}
74+
};
75+
var discoveryDocument = await this.HttpClient.GetDiscoveryDocumentAsync(discoveryRequest, cancellationToken).ConfigureAwait(false);
76+
if (string.IsNullOrWhiteSpace(discoveryDocument.TokenEndpoint)) throw new NullReferenceException($"The token endpoint is not documented by the OIDC discovery document.{(discoveryDocument.IsError ? $" Discovery error [{discoveryDocument.ErrorType}]: {discoveryDocument.Error}" : string.Empty)}");
6977
tokenEndpoint = new(discoveryDocument.TokenEndpoint!);
7078
}
7179
else if (configuration is OAuth2AuthenticationSchemeDefinition oauth2) tokenEndpoint = oauth2.Endpoints.Token;

0 commit comments

Comments
 (0)