Skip to content

Commit 7c84676

Browse files
authored
Merge branch 'master' into ft/3397-tags-external-docs
2 parents c29e05d + ad4cec0 commit 7c84676

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This repo publishes to two different NPM packages:
1818
For the older version of swagger-ui, refer to the [*2.x branch*](https://github.com/swagger-api/swagger-ui/tree/2.x).
1919

2020
## Compatibility
21-
The OpenAPI Specification has undergone 4 revisions since initial creation in 2010. Compatibility between swagger-ui and the OpenAPI Specification is as follows:
21+
The OpenAPI Specification has undergone 5 revisions since initial creation in 2010. Compatibility between swagger-ui and the OpenAPI Specification is as follows:
2222

2323
Swagger UI Version | Release Date | OpenAPI Spec compatibility | Notes
2424
------------------ | ------------ | -------------------------- | -----
@@ -97,7 +97,8 @@ To use swagger-ui's bundles, you should take a look at the [source of swagger-ui
9797

9898
#### OAuth2 configuration
9999
You can configure OAuth2 authorization by calling `initOAuth` method with passed configs under the instance of `SwaggerUIBundle`
100-
default `client_id` and `client_secret`, `realm`, an application name `appName`, `scopeSeparator`, `additionalQueryStringParams`.
100+
default `client_id` and `client_secret`, `realm`, an application name `appName`, `scopeSeparator`, `additionalQueryStringParams`,
101+
`useBasicAuthenticationWithAccessCodeGrant`.
101102

102103
Config Name | Description
103104
--- | ---
@@ -107,6 +108,7 @@ realm | realm query parameter (for oauth1) added to `authorizationUrl` and `toke
107108
appName | application name, displayed in authorization popup. MUST be a string
108109
scopeSeparator | scope separator for passing scopes, encoded before calling, default value is a space (encoded value `%20`). MUST be a string
109110
additionalQueryStringParams | Additional query parameters added to `authorizationUrl` and `tokenUrl`. MUST be an object
111+
useBasicAuthenticationWithAccessCodeGrant | Only activated for the `accessCode` flow. During the `authorization_code` request to the `tokenUrl`, pass the [Client Password](https://tools.ietf.org/html/rfc6749#section-2.3.1) using the HTTP Basic Authentication scheme (`Authorization` header with `Basic base64encoded[client_id:client_secret]`). The default is `false`
110112

111113
```
112114
const ui = SwaggerUIBundle({...})

dist/swagger-ui-bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/swagger-ui.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/oauth2-authorize.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,21 @@ export default function authorize ( { auth, authActions, errActions, configs, au
6868

6969
// pass action authorizeOauth2 and authentication data through window
7070
// to authorize with oauth2
71+
72+
let callback
73+
if (flow === "implicit") {
74+
callback = authActions.preAuthorizeImplicit
75+
} else if (authConfigs.useBasicAuthenticationWithAccessCodeGrant) {
76+
callback = authActions.authorizeAccessCodeWithBasicAuthentication
77+
} else {
78+
callback = authActions.authorizeAccessCodeWithFormParams
79+
}
80+
7181
win.swaggerUIRedirectOauth2 = {
7282
auth: auth,
7383
state: state,
7484
redirectUrl: redirectUrl,
75-
callback: flow === "implicit" ? authActions.preAuthorizeImplicit : authActions.authorizeAccessCode,
85+
callback: callback,
7686
errCb: errActions.newAuthErr
7787
}
7888

src/core/plugins/auth/actions.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const authorizeApplication = ( auth ) => ( { authActions } ) => {
111111
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth, headers })
112112
}
113113

114-
export const authorizeAccessCode = ( { auth, redirectUrl } ) => ( { authActions } ) => {
114+
export const authorizeAccessCodeWithFormParams = ( { auth, redirectUrl } ) => ( { authActions } ) => {
115115
let { schema, name, clientId, clientSecret } = auth
116116
let form = {
117117
grant_type: "authorization_code",
@@ -124,6 +124,21 @@ export const authorizeAccessCode = ( { auth, redirectUrl } ) => ( { authActions
124124
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth})
125125
}
126126

127+
export const authorizeAccessCodeWithBasicAuthentication = ( { auth, redirectUrl } ) => ( { authActions } ) => {
128+
let { schema, name, clientId, clientSecret } = auth
129+
let headers = {
130+
Authorization: "Basic " + btoa(clientId + ":" + clientSecret)
131+
}
132+
let form = {
133+
grant_type: "authorization_code",
134+
code: auth.code,
135+
client_id: clientId,
136+
redirect_uri: redirectUrl
137+
}
138+
139+
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth, headers})
140+
}
141+
127142
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => {
128143
let { body, query={}, headers={}, name, url, auth } = data
129144
let { additionalQueryStringParams } = authSelectors.getConfigs() || {}

0 commit comments

Comments
 (0)