Skip to content

Commit b8cf502

Browse files
authored
Merge branch 'master' into master
2 parents 230f4a8 + ab53122 commit b8cf502

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
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({...})

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"ieee754": "^1.1.8",
4444
"immutable": "^3.x.x",
4545
"js-yaml": "^3.5.5",
46-
"less": "2.7.1",
4746
"lodash": "4.17.2",
4847
"matcher": "^0.1.2",
4948
"memoizee": "0.4.1",

src/core/components/operations.jsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export default class Operations extends React.Component {
6666
taggedOps.map( (tagObj, tag) => {
6767
let operations = tagObj.get("operations")
6868
let tagDescription = tagObj.getIn(["tagDetails", "description"], null)
69+
let tagExternalDocsDescription = tagObj.getIn(["tagDetails", "externalDocs", "description"])
70+
let tagExternalDocsUrl = tagObj.getIn(["tagDetails", "externalDocs", "url"])
6971

7072
let isShownKey = ["operations-tag", tag]
7173
let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")
@@ -89,6 +91,22 @@ export default class Operations extends React.Component {
8991
</small>
9092
}
9193

94+
<div>
95+
{ !tagExternalDocsDescription ? null :
96+
<small>
97+
{ tagExternalDocsDescription }
98+
{ tagExternalDocsUrl ? ": " : null }
99+
{ tagExternalDocsUrl ?
100+
<a
101+
href={tagExternalDocsUrl}
102+
onClick={(e) => e.stopPropagation()}
103+
target={"_blank"}
104+
>{tagExternalDocsUrl}</a> : null
105+
}
106+
</small>
107+
}
108+
</div>
109+
92110
<button className="expand-operation" title="Expand operation" onClick={() => layoutActions.show(isShownKey, !showTag)}>
93111
<svg className="arrow" width="20" height="20">
94112
<use xlinkHref={showTag ? "#large-arrow-down" : "#large-arrow"} />

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)