Send redirect url when authenticating with oauth2-authorization_code
also fix indentations of files
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
function run () {
|
function run () {
|
||||||
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||||
var sentState = oauth2.state;
|
var sentState = oauth2.state;
|
||||||
|
var redirectUrl = oauth2.redirectUrl;
|
||||||
var isValid, qp, arr;
|
var isValid, qp, arr;
|
||||||
|
|
||||||
qp = (window.location.hash || location.search).substring(1);
|
qp = (window.location.hash || location.search).substring(1);
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
if (qp.code) {
|
if (qp.code) {
|
||||||
delete oauth2.state;
|
delete oauth2.state;
|
||||||
oauth2.auth.code = qp.code;
|
oauth2.auth.code = qp.code;
|
||||||
oauth2.callback(oauth2.auth);
|
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||||
} else {
|
} else {
|
||||||
oauth2.errCb({
|
oauth2.errCb({
|
||||||
authId: oauth2.auth.name,
|
authId: oauth2.auth.name,
|
||||||
@@ -45,9 +46,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid});
|
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
||||||
}
|
}
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export default function authorize ( { auth, authActions, errActions, configs, au
|
|||||||
win.swaggerUIRedirectOauth2 = {
|
win.swaggerUIRedirectOauth2 = {
|
||||||
auth: auth,
|
auth: auth,
|
||||||
state: state,
|
state: state,
|
||||||
|
redirectUrl: redirectUrl,
|
||||||
callback: flow === "implicit" ? authActions.preAuthorizeImplicit : authActions.authorizeAccessCode,
|
callback: flow === "implicit" ? authActions.preAuthorizeImplicit : authActions.authorizeAccessCode,
|
||||||
errCb: errActions.newAuthErr
|
errCb: errActions.newAuthErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,9 +82,14 @@ export const authorizePassword = ( auth ) => ( { authActions } ) => {
|
|||||||
headers.Authorization = "Basic " + btoa(username + ":" + password)
|
headers.Authorization = "Basic " + btoa(username + ":" + password)
|
||||||
} else {
|
} else {
|
||||||
Object.assign(form, {username}, {password})
|
Object.assign(form, {username}, {password})
|
||||||
|
|
||||||
if ( passwordType === "query") {
|
if ( passwordType === "query") {
|
||||||
if ( clientId ) { query.client_id = clientId }
|
if ( clientId ) {
|
||||||
if ( clientSecret ) { query.client_secret = clientSecret }
|
query.client_id = clientId
|
||||||
|
}
|
||||||
|
if ( clientSecret ) {
|
||||||
|
query.client_secret = clientSecret
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Object.assign(form, {client_id: clientId}, {client_secret: clientSecret})
|
Object.assign(form, {client_id: clientId}, {client_secret: clientSecret})
|
||||||
}
|
}
|
||||||
@@ -105,17 +110,17 @@ export const authorizeApplication = ( auth ) => ( { authActions } ) => {
|
|||||||
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth })
|
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authorizeAccessCode = ( auth ) => ( { authActions } ) => {
|
export const authorizeAccessCode = ( { auth, redirectUrl } ) => ( { authActions } ) => {
|
||||||
let { schema, name, clientId, clientSecret } = auth
|
let { schema, name, clientId, clientSecret } = auth
|
||||||
let form = {
|
let form = {
|
||||||
grant_type: "authorization_code",
|
grant_type: "authorization_code",
|
||||||
code: auth.code,
|
code: auth.code,
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
client_secret: clientSecret
|
client_secret: clientSecret,
|
||||||
}
|
redirect_uri: redirectUrl
|
||||||
|
}
|
||||||
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth})
|
|
||||||
|
|
||||||
|
return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => {
|
export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => {
|
||||||
@@ -140,41 +145,42 @@ export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, aut
|
|||||||
query: query,
|
query: query,
|
||||||
body: body
|
body: body
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
let token = JSON.parse(response.data)
|
let token = JSON.parse(response.data)
|
||||||
let error = token && ( token.error || "" )
|
let error = token && ( token.error || "" )
|
||||||
let parseError = token && ( token.parseError || "" )
|
let parseError = token && ( token.parseError || "" )
|
||||||
|
|
||||||
if ( !response.ok ) {
|
if ( !response.ok ) {
|
||||||
errActions.newAuthErr( {
|
|
||||||
authId: name,
|
|
||||||
level: "error",
|
|
||||||
source: "auth",
|
|
||||||
message: response.statusText
|
|
||||||
} )
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( error || parseError ) {
|
|
||||||
errActions.newAuthErr({
|
|
||||||
authId: name,
|
|
||||||
level: "error",
|
|
||||||
source: "auth",
|
|
||||||
message: JSON.stringify(token)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
authActions.authorizeOauth2({ auth, token})
|
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
let err = new Error(e)
|
|
||||||
errActions.newAuthErr( {
|
errActions.newAuthErr( {
|
||||||
authId: name,
|
authId: name,
|
||||||
level: "error",
|
level: "error",
|
||||||
source: "auth",
|
source: "auth",
|
||||||
message: err.message
|
message: response.statusText
|
||||||
} ) })
|
} )
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( error || parseError ) {
|
||||||
|
errActions.newAuthErr({
|
||||||
|
authId: name,
|
||||||
|
level: "error",
|
||||||
|
source: "auth",
|
||||||
|
message: JSON.stringify(token)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
authActions.authorizeOauth2({ auth, token})
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
let err = new Error(e)
|
||||||
|
errActions.newAuthErr( {
|
||||||
|
authId: name,
|
||||||
|
level: "error",
|
||||||
|
source: "auth",
|
||||||
|
message: err.message
|
||||||
|
} )
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function configureAuth(payload) {
|
export function configureAuth(payload) {
|
||||||
|
|||||||
Reference in New Issue
Block a user