Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add oauth config setting to enable/disable pkce extension #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type OAuthConfig struct {

// The name to display for the application in the authentication popup.
AppName string

// Use the Proof Key for Code Exchange extension to the authorization code flow
UsePkce bool
}

// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
Expand Down Expand Up @@ -286,7 +289,8 @@ window.onload = function() {
ui.initOAuth({
clientId: "{{.OAuth.ClientId}}",
realm: "{{.OAuth.Realm}}",
appName: "{{.OAuth.AppName}}"
appName: "{{.OAuth.AppName}}",
usePkceWithAuthorizationCodeGrant: {{.OAuth.UsePkce}}
})
{{end}}

Expand Down
5 changes: 4 additions & 1 deletion swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ func TestConfigWithOAuth(t *testing.T) {
assert.Contains(t, body, `ui.initOAuth({
clientId: "my-client-id",
realm: "my-realm",
appName: "My App Name"
appName: "My App Name",
usePkceWithAuthorizationCodeGrant: false
})`)
}

Expand Down Expand Up @@ -419,11 +420,13 @@ func TestOAuth(t *testing.T) {
ClientId: "my-client-id",
Realm: "my-realm",
AppName: "My App Name",
UsePkce: true,
}
OAuth(&expected)(&cfg)
assert.Equal(t, expected.ClientId, cfg.OAuth.ClientId)
assert.Equal(t, expected.Realm, cfg.OAuth.Realm)
assert.Equal(t, expected.AppName, cfg.OAuth.AppName)
assert.Equal(t, expected.UsePkce, cfg.OAuth.UsePkce)
}

func TestOAuthNil(t *testing.T) {
Expand Down