[auth] Added display of oauth2
This commit is contained in:
8134
dist/swagger-ui.js
vendored
8134
dist/swagger-ui.js
vendored
File diff suppressed because one or more lines are too long
20
dist/swagger-ui.min.js
vendored
20
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -246,6 +246,7 @@ window.SwaggerUi = Backbone.Router.extend({
|
||||
});
|
||||
|
||||
window.SwaggerUi.Views = {};
|
||||
window.SwaggerUi.Models = {};
|
||||
window.SwaggerUi.partials = {};
|
||||
window.SwaggerUi.utils = {};
|
||||
|
||||
|
||||
7
src/main/javascript/models/Oauth2Model.js
Normal file
7
src/main/javascript/models/Oauth2Model.js
Normal file
@@ -0,0 +1,7 @@
|
||||
//'use strict';
|
||||
//
|
||||
//SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
|
||||
// validate: function () {
|
||||
//
|
||||
// }
|
||||
//});
|
||||
@@ -5,6 +5,7 @@ window.SwaggerUi.utils = {
|
||||
var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions;
|
||||
var oauth2Arr = [];
|
||||
var authsArr = [];
|
||||
var utils = window.SwaggerUi.utils;
|
||||
|
||||
if (!Array.isArray(security)) { return null; }
|
||||
|
||||
@@ -23,12 +24,14 @@ window.SwaggerUi.utils = {
|
||||
delete singleOauth2Security[key].scopes[i];
|
||||
}
|
||||
}
|
||||
singleOauth2Security[key].scopes = utils.parseOauth2Scopes(singleOauth2Security[key].scopes);
|
||||
} else {
|
||||
singleSecurity[key] = auths[key];
|
||||
}
|
||||
} else {
|
||||
if (item[key].type === 'oauth2') {
|
||||
singleOauth2Security[key] = item[key];
|
||||
singleOauth2Security[key].scopes = utils.parseOauth2Scopes(singleOauth2Security[key].scopes);
|
||||
} else {
|
||||
singleSecurity[key] = item[key];
|
||||
}
|
||||
@@ -43,5 +46,16 @@ window.SwaggerUi.utils = {
|
||||
auths : authsArr,
|
||||
oauth2: oauth2Arr
|
||||
};
|
||||
},
|
||||
|
||||
parseOauth2Scopes: function (scopes) {
|
||||
var result = [];
|
||||
var key;
|
||||
|
||||
for (key in scopes) {
|
||||
result.push({scope: key, description: scopes[key]});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@@ -14,7 +14,7 @@ SwaggerUi.Views.AuthButtonView = Backbone.View.extend({
|
||||
this.options = opts || {};
|
||||
this.options.data = this.options.data || {};
|
||||
this.router = this.options.router;
|
||||
this.auths = this.options.data.auths;
|
||||
this.auths = this.options.data.oauth2.concat(this.options.data.auths);
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
@@ -72,14 +72,16 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
|
||||
var authEl;
|
||||
var type = authModel.get('type');
|
||||
|
||||
//todo refactor move view name into var and call new with it.
|
||||
if (type === 'apiKey') {
|
||||
authEl = new SwaggerUi.Views.ApiKeyAuthView({model: authModel, router: this.router}).render().el;
|
||||
this.$innerEl.append(authEl);
|
||||
} else if (type === 'basic' && this.$innerEl.find('.basic_auth_container').length === 0) {
|
||||
authEl = new SwaggerUi.Views.BasicAuthView({model: authModel, router: this.router}).render().el;
|
||||
this.$innerEl.append(authEl);
|
||||
} else if (type === 'oauth2') {
|
||||
authEl = new SwaggerUi.Views.Oauth2View({model: authModel, router: this.router}).render().el;
|
||||
}
|
||||
|
||||
this.$innerEl.append(authEl);
|
||||
},
|
||||
|
||||
isValidCollection: function () {
|
||||
|
||||
19
src/main/javascript/view/Oauth2View.js
Normal file
19
src/main/javascript/view/Oauth2View.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
SwaggerUi.Views.Oauth2View = Backbone.View.extend({
|
||||
events: {
|
||||
'change .oauth-scope': 'scopeChange'
|
||||
},
|
||||
|
||||
template: Handlebars.templates.oauth2,
|
||||
|
||||
render: function () {
|
||||
$(this.el).html(this.template(this.model.toJSON()));
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
scopeChange: function () {
|
||||
|
||||
}
|
||||
});
|
||||
21
src/main/template/oauth2.handlebars
Normal file
21
src/main/template/oauth2.handlebars
Normal file
@@ -0,0 +1,21 @@
|
||||
<p>{{description}}</p>
|
||||
<p>Select OAuth2.0 Scopes</p>
|
||||
<p>Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.
|
||||
<a href="#">Learn how to use</a>
|
||||
</p>
|
||||
<p><strong> {{appName}} </strong> API requires the following scopes. Select which ones you want to grant to Swagger UI.</p>
|
||||
<p>Authorization URL: {{authorizationUrl}}</p>
|
||||
<p>flow: {{flow}}</p>
|
||||
<ul class="api-popup-scopes">
|
||||
{{#each scopes}}
|
||||
<li>
|
||||
<input class="oauth-scope" type="checkbox" scope="{{scope}}" oauthtype="{{OAuthSchemeKey}}"/>
|
||||
<label>{{scope}}</label><br/>
|
||||
<span class="api-scope-desc">{{description}}
|
||||
{{#if OAuthSchemeKey}}
|
||||
({{OAuthSchemeKey}})
|
||||
{{/if}}
|
||||
</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
Reference in New Issue
Block a user