Skip to content

Commit

Permalink
feat(core/oauth): support issuer URL overriding (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
tessig authored Mar 25, 2022
1 parent 1854abc commit fa5bd34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/oauth/application/authmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (am *AuthManager) Inject(logger flamingo.Logger, router *web.Router, config
TokenExtras config.Slice `inject:"config:core.oauth.tokenExtras"`
DebugMode bool `inject:"config:flamingo.debug.mode"`
Enabled bool `inject:"config:core.oauth.enabled"`
OverrideIssuerURL string `inject:"config:core.oauth.overrideIssuerURL"`
}) {
am.logger = logger.WithField(flamingo.LogKeyModule, "oauth")
am.router = router
Expand All @@ -110,13 +111,18 @@ func (am *AuthManager) Inject(logger flamingo.Logger, router *web.Router, config
return
}

ctx := context.Background()
if config.OverrideIssuerURL != "" {
ctx = oidc.InsecureIssuerURLContext(ctx, config.OverrideIssuerURL)
}

var err error
am.openIDProvider, err = oidc.NewProvider(context.Background(), config.Server)
am.openIDProvider, err = oidc.NewProvider(ctx, config.Server)
if err != nil {
if config.DebugMode {
am.logger.Error(err)
} else {
//panic on err since we really expect a valid authmanager state and application is in a failed state otherwise
// panic on err since we really expect a valid authmanager state and application is in a failed state otherwise
panic(err)
}
}
Expand Down Expand Up @@ -161,7 +167,7 @@ func (am *AuthManager) OpenIDProvider() *oidc.Provider {
return am.openIDProvider
}

//OAuthCtx - returns ctx that should be used to pass to oauth2 lib - it enables logging for Debug reasons
// OAuthCtx - returns ctx that should be used to pass to oauth2 lib - it enables logging for Debug reasons
func (am *AuthManager) OAuthCtx(ctx context.Context) context.Context {
if os.Getenv("OAUTHDEBUG") == "1" {
oauthHTTPClient := &http.Client{
Expand Down
1 change: 1 addition & 0 deletions core/oauth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ core oauth: {
useFake: bool | *false
fakeUserData: [string]: _
fakeLoginTemplate: string | *""
overrideIssuerURL: string | *""
scopes: [...string] | *["profile", "email"]
claims: {
idToken: [...string]
Expand Down

0 comments on commit fa5bd34

Please sign in to comment.