Merge pull request #2864 from misi/master
Implement Application/Client Credentials Flow
This commit is contained in:
@@ -145,7 +145,7 @@ export default class Oauth2 extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
( flow === IMPLICIT || flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) &&
|
( flow === APPLICATION || flow === IMPLICIT || flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) &&
|
||||||
( !isAuthorized || isAuthorized && this.state.clientId) && <Row>
|
( !isAuthorized || isAuthorized && this.state.clientId) && <Row>
|
||||||
<label htmlFor="client_id">client_id:</label>
|
<label htmlFor="client_id">client_id:</label>
|
||||||
<Col tablet={10} desktop={10}>
|
<Col tablet={10} desktop={10}>
|
||||||
@@ -159,7 +159,7 @@ export default class Oauth2 extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
( flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) && <Row>
|
( flow === APPLICATION || flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) && <Row>
|
||||||
<label htmlFor="client_secret">client_secret:</label>
|
<label htmlFor="client_secret">client_secret:</label>
|
||||||
<Col tablet={10} desktop={10}>
|
<Col tablet={10} desktop={10}>
|
||||||
{
|
{
|
||||||
@@ -205,7 +205,7 @@ export default class Oauth2 extends React.Component {
|
|||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
<div className="auth-btn-wrapper">
|
<div className="auth-btn-wrapper">
|
||||||
{ isValid && flow !== APPLICATION &&
|
{ isValid &&
|
||||||
( isAuthorized ? <Button className="btn modal-btn auth authorize" onClick={ this.logout }>Logout</Button>
|
( isAuthorized ? <Button className="btn modal-btn auth authorize" onClick={ this.logout }>Logout</Button>
|
||||||
: <Button className="btn modal-btn auth authorize" onClick={ this.authorize }>Authorize</Button>
|
: <Button className="btn modal-btn auth authorize" onClick={ this.authorize }>Authorize</Button>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ export default function authorize ( auth, authActions, errActions, configs ) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flow === "application") {
|
||||||
|
authActions.authorizeOauth2Application(auth)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// todo move to parser
|
// todo move to parser
|
||||||
if ( !redirectUrl ) {
|
if ( !redirectUrl ) {
|
||||||
errActions.newAuthErr( {
|
errActions.newAuthErr( {
|
||||||
|
|||||||
@@ -119,3 +119,35 @@ export const authorizePassword = ( auth ) => ( { fn, authActions, errActions } )
|
|||||||
})
|
})
|
||||||
.catch(err => { errActions.newAuthErr( err ) })
|
.catch(err => { errActions.newAuthErr( err ) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const authorizeOauth2Application = ( auth ) => ( { fn, authActions, errActions } ) => {
|
||||||
|
let { schema, scopes, name, clientId, clientSecret } = auth
|
||||||
|
|
||||||
|
fn.fetch(schema.get("tokenUrl"), {
|
||||||
|
method: "post", headers: {
|
||||||
|
"Accept":"application/json, text/plain, */*",
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded"
|
||||||
|
},
|
||||||
|
body: "grant_type=client_credentials" +
|
||||||
|
"&client_id=" + encodeURIComponent(clientId) +
|
||||||
|
"&client_secret=" + encodeURIComponent(clientSecret) +
|
||||||
|
"&scope=" + encodeURIComponent(scopes.join(scopeSeparator))
|
||||||
|
})
|
||||||
|
.then(function (response) {
|
||||||
|
if ( !response.ok ) {
|
||||||
|
errActions.newAuthErr( {
|
||||||
|
authId: name,
|
||||||
|
level: "error",
|
||||||
|
source: "auth",
|
||||||
|
message: response.statusText
|
||||||
|
} )
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
response.json()
|
||||||
|
.then(function (json){
|
||||||
|
authActions.authorizeOauth2({ auth, token: json})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => { errActions.newAuthErr( err ) })
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user