Implement OAuth2 client authentication for password and application flow

This commit is contained in:
TANAKA Koichi
2016-11-12 23:17:10 +09:00
parent f2a1caa379
commit 3494d44d3f
4 changed files with 97 additions and 32 deletions

View File

@@ -3,7 +3,8 @@
SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
defaults: {
scopes: {},
isPasswordFlow: false
isPasswordFlow: false,
clientAuthenticationType: 'none'
},
initialize: function () {
@@ -21,7 +22,12 @@ SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
this.attributes = attributes;
}
this.set('isPasswordFlow', attributes.flow && attributes.flow === 'password');
if (this.attributes && this.attributes.flow) {
var flow = this.attributes.flow;
this.set('isPasswordFlow', flow === 'password');
this.set('requireClientAuthentication', flow === 'application');
this.set('clientAuthentication', flow === 'password' || flow === 'application');
}
this.on('change', this.validate);
},
@@ -43,6 +49,11 @@ SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
return false;
}
if (this.get('clientAuthenticationType') in ['basic', 'request-body'] &&
(!this.get('clientId'))) {
return false;
}
var scp = this.get('scopes');
var idx = _.findIndex(scp, function (o) {
return o.checked === true;