diff --git a/lib/swagger-oauth.js b/lib/swagger-oauth.js index 576fcd33bf9..30646386476 100644 --- a/lib/swagger-oauth.js +++ b/lib/swagger-oauth.js @@ -4,6 +4,7 @@ var popupDialog; var clientId; var realm; var redirect_uri; +var state; var clientSecret; var scopeSeparator; var additionalQueryStringParams; @@ -11,25 +12,33 @@ var additionalQueryStringParams; function handleLogin() { var scopes = []; - var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions; + var auths = window.swaggerUi.api.authSchemes || window.swaggerUi.api.securityDefinitions, + passwordFlow = false; + if(auths) { var key; var defs = auths; for(key in defs) { var auth = defs[key]; - if(auth.type === 'oauth2' && auth.scopes) { - var scope; - if(Array.isArray(auth.scopes)) { - // 1.2 support - var i; - for(i = 0; i < auth.scopes.length; i++) { - scopes.push(auth.scopes[i]); + if(auth.type === 'oauth2') { + passwordFlow = auth.flow === 'password'; + + if (auth.scopes) { + var scope; + if(Array.isArray(auth.scopes)) { + // 1.2 support + var i; + for(i = 0; i < auth.scopes.length; i++) { + scope = auth.scopes[i]; + scope.OAuthSchemeKey = key; + scopes.push(scope); + } } - } - else { - // 2.0 support - for(scope in auth.scopes) { - scopes.push({scope: scope, description: auth.scopes[scope], OAuthSchemeKey: key}); + else { + // 2.0 support + for(scope in auth.scopes) { + scopes.push({scope: scope, description: auth.scopes[scope], OAuthSchemeKey: key}); + } } } } @@ -41,29 +50,46 @@ function handleLogin() { appName = window.swaggerUi.api.info.title; } - $('.api-popup-dialog').remove(); - popupDialog = $( - [ - '
', - '
Select OAuth2.0 Scopes
', - '
', - '

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.', - 'Learn how to use', - '

', - '

' + appName + ' API requires the following scopes. Select which ones you want to grant to Swagger UI.

', - '', - '

', - '
', - '
', - '
'].join('')); + $('.api-popup-dialog').remove(); + + popupDialog = ['
']; + + if (passwordFlow === true) { + popupDialog = popupDialog.concat([ + '
', + 'Password Auth', + '
', + '
', + '
' + ]); + } + + popupDialog = $(popupDialog.concat([ + '
Select OAuth2.0 Scopes
', + '
', + '

', + '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. ', + 'Learn how to use', + '

', + '

', + '' + appName + ' API requires the following scopes. Select which ones you want to grant to Swagger UI.', + '

', + '', + '

', + '
', + '', + '', + '
', + '
', + '
']).join('')); + $(document.body).append(popupDialog); //TODO: only display applicable scopes (will need to pass them into handleLogin) popup = popupDialog.find('ul.api-popup-scopes').empty(); for (i = 0; i < scopes.length; i ++) { scope = scopes[i]; - str = '
  • ' + '
  • ' + '