diff --git a/packages/insomnia-app/app/models/request.js b/packages/insomnia-app/app/models/request.js index a7feb01d1..b3790b00d 100644 --- a/packages/insomnia-app/app/models/request.js +++ b/packages/insomnia-app/app/models/request.js @@ -153,6 +153,7 @@ export function newAuth (type: string, oldAuth: RequestAuthentication = {}): Req issuer: '', subject: '', audience: '', + additionalClaims: '', keyId: '', privateKey: '' }; diff --git a/packages/insomnia-app/app/network/authentication.js b/packages/insomnia-app/app/network/authentication.js index ef8947c6c..99a15da67 100644 --- a/packages/insomnia-app/app/network/authentication.js +++ b/packages/insomnia-app/app/network/authentication.js @@ -73,10 +73,27 @@ export async function getAuthHeader ( } if (authentication.type === AUTH_ASAP) { - const {issuer, subject, audience, keyId, privateKey} = authentication; + const {issuer, subject, audience, keyId, additionalClaims, privateKey} = authentication; const generator = jwtAuthentication.client.create(); - const claims = {iss: issuer, sub: subject, aud: audience}; + let claims = {iss: issuer, sub: subject, aud: audience}; + + let parsedAdditionalClaims; + + try { + parsedAdditionalClaims = JSON.parse(additionalClaims); + } catch (err) { + throw new Error(`Unable to parse additional-claims: ${err}`); + } + + if (parsedAdditionalClaims) { + if (typeof parsedAdditionalClaims !== 'object') { + throw new Error(`additional-claims must be an object recieved: '${typeof parsedAdditionalClaims}' instead`); + } + + claims = Object.assign(parsedAdditionalClaims, claims); + } + const options = { privateKey, kid: keyId diff --git a/packages/insomnia-app/app/ui/components/editors/auth/asap-auth.js b/packages/insomnia-app/app/ui/components/editors/auth/asap-auth.js index d64ef6540..17ebbcbf3 100644 --- a/packages/insomnia-app/app/ui/components/editors/auth/asap-auth.js +++ b/packages/insomnia-app/app/ui/components/editors/auth/asap-auth.js @@ -55,24 +55,35 @@ class AsapAuth extends React.PureComponent { const asapIssuer = this.renderTextInput( 'Issuer (iss)', 'issuer', + 'text/plain', value => this._handleChangeProperty('issuer', value) ); const asapSubject = this.renderTextInput( 'Subject (sub)', 'subject', - value => this._handleChangeProperty('subject', value) + 'text/plain', + (value) => this._handleChangeProperty('subject', value) ); const asapAudience = this.renderTextInput( 'Audience (aud)', 'audience', + 'text/plain', value => this._handleChangeProperty('audience', value) ); + const asapAdditionalClaims = this.renderTextInput( + 'Additional Claims', + 'additionalClaims', + 'application/json', + (value) => this._handleChangeProperty('additionalClaims', value) + ); + const asapKeyId = this.renderTextInput( 'Key ID (kid)', 'keyId', + 'text/plain', value => this._handleChangeProperty('keyId', value) ); @@ -80,12 +91,13 @@ class AsapAuth extends React.PureComponent { 'Private Key', ); - return [asapIssuer, asapSubject, asapAudience, asapKeyId, asapPrivateKey]; + return [asapIssuer, asapSubject, asapAudience, asapAdditionalClaims, asapKeyId, asapPrivateKey]; } renderTextInput ( label: string, property: string, + mode: string, onChange: Function ): React.Element<*> { const {handleRender, handleGetRenderContext, authentication, nunjucksPowerUserMode} = this.props; @@ -103,6 +115,7 @@ class AsapAuth extends React.PureComponent { })}>