diff --git a/src/core/components/auth/oauth2.jsx b/src/core/components/auth/oauth2.jsx index 48fe946e..ec24eb01 100644 --- a/src/core/components/auth/oauth2.jsx +++ b/src/core/components/auth/oauth2.jsx @@ -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) && @@ -159,7 +159,7 @@ export default class Oauth2 extends React.Component { } { - ( flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) && + ( flow === APPLICATION || flow === ACCESS_CODE || ( flow === PASSWORD && this.state.passwordType!== "none") ) && { @@ -205,7 +205,7 @@ export default class Oauth2 extends React.Component { } ) }
- { isValid && flow !== APPLICATION && + { isValid && ( isAuthorized ? : ) diff --git a/src/core/oauth2-authorize.js b/src/core/oauth2-authorize.js index d02b8122..d8babd95 100644 --- a/src/core/oauth2-authorize.js +++ b/src/core/oauth2-authorize.js @@ -14,6 +14,11 @@ export default function authorize ( auth, authActions, errActions, configs ) { return } + if (flow === "application") { + authActions.authorizeOauth2Application(auth) + return + } + // todo move to parser if ( !redirectUrl ) { errActions.newAuthErr( { diff --git a/src/core/plugins/auth/actions.js b/src/core/plugins/auth/actions.js index 79cd2a40..8e00d392 100644 --- a/src/core/plugins/auth/actions.js +++ b/src/core/plugins/auth/actions.js @@ -119,3 +119,35 @@ export const authorizePassword = ( auth ) => ( { fn, authActions, errActions } ) }) .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 ) }) +}