From bfe7b70ea4ec1a176c4daeb11eb20c29fa86ddd5 Mon Sep 17 00:00:00 2001 From: Exulansis Date: Tue, 16 Apr 2019 18:31:23 +0200 Subject: [PATCH 1/5] Description field on authentication request --- .../interactionTokens/authentication.data.ts | 1 + .../interactionTokens/authentication.test.ts | 2 +- ts/identityWallet/identityWallet.ts | 12 +++++++---- ts/identityWallet/types.ts | 9 ++++++--- ts/interactionTokens/authentication.ts | 20 +++++++++++++++++++ .../interactionTokens.types.ts | 1 + 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tests/data/interactionTokens/authentication.data.ts b/tests/data/interactionTokens/authentication.data.ts index 206f80ad..d3b9b83b 100644 --- a/tests/data/interactionTokens/authentication.data.ts +++ b/tests/data/interactionTokens/authentication.data.ts @@ -1,3 +1,4 @@ export const jsonAuthentication = { callbackURL: 'https://me.test.io', + description: 'Test service usage', } diff --git a/tests/interactionTokens/authentication.test.ts b/tests/interactionTokens/authentication.test.ts index 37fc58e2..45107c96 100644 --- a/tests/interactionTokens/authentication.test.ts +++ b/tests/interactionTokens/authentication.test.ts @@ -6,7 +6,6 @@ describe('Authentication', () => { let auth: Authentication /* Implicitly tests toJSON too */ - it('Should implement static fromJSON', () => { auth = Authentication.fromJSON(jsonAuthentication) expect(auth.toJSON()).to.deep.eq(jsonAuthentication) @@ -14,5 +13,6 @@ describe('Authentication', () => { it('Should implement getters method', () => { expect(auth.callbackURL).to.eq(jsonAuthentication.callbackURL) + expect(auth.description).to.eq(jsonAuthentication.description) }) }) diff --git a/ts/identityWallet/identityWallet.ts b/ts/identityWallet/identityWallet.ts index 0a890ebd..ea679b27 100644 --- a/ts/identityWallet/identityWallet.ts +++ b/ts/identityWallet/identityWallet.ts @@ -2,7 +2,7 @@ import { BaseMetadata } from 'cred-types-jolocom-core' import { Credential } from '../credentials/credential/credential' import { SignedCredential } from '../credentials/signedCredential/signedCredential' import { - AuthRequestCreationArgs, + AuthCreationArgs, CredentialOfferRequestCreationArgs, CredentialOfferResponseCreationArgs, CredentialShareRequestCreationArgs, @@ -10,7 +10,7 @@ import { IIdentityWalletCreateArgs, PaymentRequestCreationArgs, PaymentResponseCreationArgs, - PublicKeyMap, + PublicKeyMap } from './types' import { Identity } from '../identity/identity' import { JSONWebToken, JWTEncodable } from '../interactionTokens/JSONWebToken' @@ -222,11 +222,15 @@ export class IdentityWallet { */ private createAuth = async ( - authArgs: AuthRequestCreationArgs, + authArgs: AuthCreationArgs, pass: string, receivedJWT?: JSONWebToken, ) => { - const authenticationReq = Authentication.fromJSON(authArgs) + const authenticationReq = Authentication.fromJSON({ + description: 'Authorization required', + ...authArgs + }) + const jwt = JSONWebToken.fromJWTEncodable(authenticationReq) jwt.interactionType = InteractionType.Authentication return this.initializeAndSign( diff --git a/ts/identityWallet/types.ts b/ts/identityWallet/types.ts index ae70b0c7..8a53da88 100644 --- a/ts/identityWallet/types.ts +++ b/ts/identityWallet/types.ts @@ -21,14 +21,17 @@ export interface IIdentityWalletCreateArgs { export type PublicKeyMap = { [key in keyof typeof KeyTypes]?: string } -export type AuthRequestCreationArgs = IAuthenticationAttrs export type CredentialShareRequestCreationArgs = ICredentialRequestAttrs export type CredentialShareResponseCreationArgs = ICredentialResponseAttrs - export type CredentialOfferRequestCreationArgs = ICredentialOfferAttrs export type CredentialOfferResponseCreationArgs = ICredentialsReceiveAttrs - export type PaymentResponseCreationArgs = IPaymentResponseAttrs + +export type AuthCreationArgs = { + callbackURL: string, + description?: string +} + export interface PaymentRequestCreationArgs { callbackURL: string description: string diff --git a/ts/interactionTokens/authentication.ts b/ts/interactionTokens/authentication.ts index 0387f41c..3ed0afa1 100644 --- a/ts/interactionTokens/authentication.ts +++ b/ts/interactionTokens/authentication.ts @@ -11,6 +11,7 @@ import { IAuthenticationAttrs } from './interactionTokens.types' @Exclude() export class Authentication { private _callbackURL: string + private _description: string /** * Get the callback url encoded in the payload @@ -31,6 +32,25 @@ export class Authentication { this._callbackURL = callbackURL } + /** + * Get the description for the required action + * @example `console.log(authentication.description) // 'Authorization required'` + */ + + @Expose() + get description(): string { + return this._description + } + + /** + * Set the description for the required action + * @example `authentication.description = 'Authorization to start the vehicle'` + */ + + set description(description: string) { + this._description = description + } + /** * Serializes the {@link Authentication} request / response as JSON-LD */ diff --git a/ts/interactionTokens/interactionTokens.types.ts b/ts/interactionTokens/interactionTokens.types.ts index 6267f3bd..f87c7dcf 100644 --- a/ts/interactionTokens/interactionTokens.types.ts +++ b/ts/interactionTokens/interactionTokens.types.ts @@ -42,6 +42,7 @@ export interface ICredentialRequest { export interface IAuthenticationAttrs { callbackURL: string + description: string } /* Related to constraint functions */ From 0a7556c94fd71336cbc0dd00d058564d829b984a Mon Sep 17 00:00:00 2001 From: Exulansis Date: Tue, 16 Apr 2019 18:37:51 +0200 Subject: [PATCH 2/5] Restored integration test --- .../integration/authentication.integration.ts | 125 +++++++++--------- 1 file changed, 63 insertions(+), 62 deletions(-) diff --git a/tests/integration/authentication.integration.ts b/tests/integration/authentication.integration.ts index 1d2071cd..b4de700e 100644 --- a/tests/integration/authentication.integration.ts +++ b/tests/integration/authentication.integration.ts @@ -1,62 +1,63 @@ -// import * as chai from 'chai' -// import * as sinonChai from 'sinon-chai' -// import { userPass, servicePass } from './integration.data' -// import { JSONWebToken } from '../../ts/interactionTokens/JSONWebToken' -// import { keyIdToDid } from '../../ts/utils/helper' -// import { jsonAuthentication } from '../data/interactionTokens/authentication.data' -// import { Authentication } from '../../ts/interactionTokens/authentication' -// import { userIdentityWallet, serviceIdentityWallet, jolocomRegistry } from './identity.integration' - -// chai.use(sinonChai) -// const expect = chai.expect - -// describe('Integration Test - Token interaction flow Authentication', () => { -// let authRequestJWT -// let authRequestEncoded -// let authResponseEncoded - -// it('Should correctly create an authentication request token by service', async () => { -// authRequestJWT = await serviceIdentityWallet.create.interactionTokens.request -// .auth(jsonAuthentication, servicePass) -// authRequestEncoded = authRequestJWT.encode() - -// expect(authRequestJWT.interactionToken).to.deep.eq(Authentication.fromJSON(jsonAuthentication)) -// expect(authRequestJWT).to.be.instanceOf(JSONWebToken) -// expect(authRequestJWT.interactionToken).to.be.instanceOf(Authentication) -// }) - -// it('Should allow for consumption of valid authentication request token by user', async () => { -// const decodedAuthRequest = JSONWebToken.decode(authRequestEncoded) -// expect(decodedAuthRequest.interactionToken).to.be.instanceOf(Authentication) - -// try { -// await userIdentityWallet.validateJWT(decodedAuthRequest, null, jolocomRegistry) -// } catch (err) { -// expect(true).to.be.false -// } - -// const authResponseJWT = await userIdentityWallet.create.interactionTokens.response.auth( -// { -// callbackURL: decodedAuthRequest.interactionToken.callbackURL -// }, -// userPass, -// decodedAuthRequest -// ) -// authResponseEncoded = authResponseJWT.encode() - -// expect(authResponseJWT.interactionToken).to.be.instanceOf(Authentication) -// expect(authResponseJWT.nonce).to.eq(decodedAuthRequest.nonce) -// expect(authResponseJWT.audience).to.eq(keyIdToDid(decodedAuthRequest.issuer)) -// }) - -// it('Should allow for consumption of valid authentication response token by service', async () => { -// const decodedAuthResponse = JSONWebToken.decode(authResponseEncoded) -// expect(decodedAuthResponse.interactionToken).to.be.instanceOf(Authentication) - -// try { -// await serviceIdentityWallet.validateJWT(decodedAuthResponse, authRequestJWT, jolocomRegistry) -// } catch (err) { -// expect(true).to.be.false -// } -// }) -// }) +import * as chai from 'chai' +import * as sinonChai from 'sinon-chai' +import { userPass, servicePass } from './integration.data' +import { JSONWebToken } from '../../ts/interactionTokens/JSONWebToken' +import { keyIdToDid } from '../../ts/utils/helper' +import { jsonAuthentication } from '../data/interactionTokens/authentication.data' +import { Authentication } from '../../ts/interactionTokens/authentication' +import { userIdentityWallet, serviceIdentityWallet, jolocomRegistry } from './identity.integration' + +chai.use(sinonChai) +const expect = chai.expect + +describe('Integration Test - Token interaction flow Authentication', () => { + let authRequestJWT + let authRequestEncoded + let authResponseEncoded + + it('Should correctly create an authentication request token by service', async () => { + authRequestJWT = await serviceIdentityWallet.create.interactionTokens.request + .auth(jsonAuthentication, servicePass) + authRequestEncoded = authRequestJWT.encode() + + expect(authRequestJWT.interactionToken).to.deep.eq(Authentication.fromJSON(jsonAuthentication)) + expect(authRequestJWT).to.be.instanceOf(JSONWebToken) + expect(authRequestJWT.interactionToken).to.be.instanceOf(Authentication) + }) + + it('Should allow for consumption of valid authentication request token by user', async () => { + const decodedAuthRequest = JSONWebToken.decode(authRequestEncoded) + expect(decodedAuthRequest.interactionToken).to.be.instanceOf(Authentication) + + try { + await userIdentityWallet.validateJWT(decodedAuthRequest, null, jolocomRegistry) + } catch (err) { + return expect(true).to.be.false + } + + const authResponseJWT = await userIdentityWallet.create.interactionTokens.response.auth( + { + callbackURL: decodedAuthRequest.interactionToken.callbackURL, + description: decodedAuthRequest.interactionToken.description, + }, + userPass, + decodedAuthRequest + ) + authResponseEncoded = authResponseJWT.encode() + + expect(authResponseJWT.interactionToken).to.be.instanceOf(Authentication) + expect(authResponseJWT.nonce).to.eq(decodedAuthRequest.nonce) + expect(authResponseJWT.audience).to.eq(keyIdToDid(decodedAuthRequest.issuer)) + }) + + it('Should allow for consumption of valid authentication response token by service', async () => { + const decodedAuthResponse = JSONWebToken.decode(authResponseEncoded) + expect(decodedAuthResponse.interactionToken).to.be.instanceOf(Authentication) + + try { + await serviceIdentityWallet.validateJWT(decodedAuthResponse, authRequestJWT, jolocomRegistry) + } catch (err) { + return expect(true).to.be.false + } + }) +}) From 06fd8f1906bb944ddfb3dfda7d9ac5f4ef099a73 Mon Sep 17 00:00:00 2001 From: Exulansis Date: Tue, 16 Apr 2019 18:39:38 +0200 Subject: [PATCH 3/5] Ran yarn:format --- .../integration/authentication.integration.ts | 46 ++++++++++++++----- ts/identityWallet/identityWallet.ts | 4 +- ts/identityWallet/types.ts | 4 +- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/integration/authentication.integration.ts b/tests/integration/authentication.integration.ts index b4de700e..b0b8384b 100644 --- a/tests/integration/authentication.integration.ts +++ b/tests/integration/authentication.integration.ts @@ -5,7 +5,11 @@ import { JSONWebToken } from '../../ts/interactionTokens/JSONWebToken' import { keyIdToDid } from '../../ts/utils/helper' import { jsonAuthentication } from '../data/interactionTokens/authentication.data' import { Authentication } from '../../ts/interactionTokens/authentication' -import { userIdentityWallet, serviceIdentityWallet, jolocomRegistry } from './identity.integration' +import { + userIdentityWallet, + serviceIdentityWallet, + jolocomRegistry, +} from './identity.integration' chai.use(sinonChai) const expect = chai.expect @@ -16,21 +20,31 @@ describe('Integration Test - Token interaction flow Authentication', () => { let authResponseEncoded it('Should correctly create an authentication request token by service', async () => { - authRequestJWT = await serviceIdentityWallet.create.interactionTokens.request - .auth(jsonAuthentication, servicePass) + authRequestJWT = await serviceIdentityWallet.create.interactionTokens.request.auth( + jsonAuthentication, + servicePass, + ) authRequestEncoded = authRequestJWT.encode() - expect(authRequestJWT.interactionToken).to.deep.eq(Authentication.fromJSON(jsonAuthentication)) + expect(authRequestJWT.interactionToken).to.deep.eq( + Authentication.fromJSON(jsonAuthentication), + ) expect(authRequestJWT).to.be.instanceOf(JSONWebToken) expect(authRequestJWT.interactionToken).to.be.instanceOf(Authentication) }) it('Should allow for consumption of valid authentication request token by user', async () => { - const decodedAuthRequest = JSONWebToken.decode(authRequestEncoded) + const decodedAuthRequest = JSONWebToken.decode( + authRequestEncoded, + ) expect(decodedAuthRequest.interactionToken).to.be.instanceOf(Authentication) try { - await userIdentityWallet.validateJWT(decodedAuthRequest, null, jolocomRegistry) + await userIdentityWallet.validateJWT( + decodedAuthRequest, + null, + jolocomRegistry, + ) } catch (err) { return expect(true).to.be.false } @@ -41,21 +55,31 @@ describe('Integration Test - Token interaction flow Authentication', () => { description: decodedAuthRequest.interactionToken.description, }, userPass, - decodedAuthRequest + decodedAuthRequest, ) authResponseEncoded = authResponseJWT.encode() expect(authResponseJWT.interactionToken).to.be.instanceOf(Authentication) expect(authResponseJWT.nonce).to.eq(decodedAuthRequest.nonce) - expect(authResponseJWT.audience).to.eq(keyIdToDid(decodedAuthRequest.issuer)) + expect(authResponseJWT.audience).to.eq( + keyIdToDid(decodedAuthRequest.issuer), + ) }) it('Should allow for consumption of valid authentication response token by service', async () => { - const decodedAuthResponse = JSONWebToken.decode(authResponseEncoded) - expect(decodedAuthResponse.interactionToken).to.be.instanceOf(Authentication) + const decodedAuthResponse = JSONWebToken.decode( + authResponseEncoded, + ) + expect(decodedAuthResponse.interactionToken).to.be.instanceOf( + Authentication, + ) try { - await serviceIdentityWallet.validateJWT(decodedAuthResponse, authRequestJWT, jolocomRegistry) + await serviceIdentityWallet.validateJWT( + decodedAuthResponse, + authRequestJWT, + jolocomRegistry, + ) } catch (err) { return expect(true).to.be.false } diff --git a/ts/identityWallet/identityWallet.ts b/ts/identityWallet/identityWallet.ts index ea679b27..016ef494 100644 --- a/ts/identityWallet/identityWallet.ts +++ b/ts/identityWallet/identityWallet.ts @@ -10,7 +10,7 @@ import { IIdentityWalletCreateArgs, PaymentRequestCreationArgs, PaymentResponseCreationArgs, - PublicKeyMap + PublicKeyMap, } from './types' import { Identity } from '../identity/identity' import { JSONWebToken, JWTEncodable } from '../interactionTokens/JSONWebToken' @@ -228,7 +228,7 @@ export class IdentityWallet { ) => { const authenticationReq = Authentication.fromJSON({ description: 'Authorization required', - ...authArgs + ...authArgs, }) const jwt = JSONWebToken.fromJWTEncodable(authenticationReq) diff --git a/ts/identityWallet/types.ts b/ts/identityWallet/types.ts index 8a53da88..26f6fa2a 100644 --- a/ts/identityWallet/types.ts +++ b/ts/identityWallet/types.ts @@ -27,8 +27,8 @@ export type CredentialOfferRequestCreationArgs = ICredentialOfferAttrs export type CredentialOfferResponseCreationArgs = ICredentialsReceiveAttrs export type PaymentResponseCreationArgs = IPaymentResponseAttrs -export type AuthCreationArgs = { - callbackURL: string, +export interface AuthCreationArgs { + callbackURL: string description?: string } From 1de9c83200cd25861a5a3ff49e89ed4b15bb625b Mon Sep 17 00:00:00 2001 From: Exulansis Date: Wed, 17 Apr 2019 13:04:05 +0200 Subject: [PATCH 4/5] Changed default auth request description --- package.json | 2 +- ts/identityWallet/identityWallet.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4c5a845b..1234b09f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ ], "typings": "js/index.d.ts", "scripts": { - "test": "yarn clean; nyc mocha --opts ./mocha.opts ./tests/**/*.test.ts", + "test": "nyc mocha --opts ./mocha.opts ./tests/**/*.test.ts", "clean": "rm -rf ./js", "prepublish": "yarn clean; yarn build", "build": "tsc -p .", diff --git a/ts/identityWallet/identityWallet.ts b/ts/identityWallet/identityWallet.ts index 016ef494..ebe72b4c 100644 --- a/ts/identityWallet/identityWallet.ts +++ b/ts/identityWallet/identityWallet.ts @@ -227,7 +227,7 @@ export class IdentityWallet { receivedJWT?: JSONWebToken, ) => { const authenticationReq = Authentication.fromJSON({ - description: 'Authorization required', + description: 'Authorize the transaction', ...authArgs, }) From 97463420fa0a57ea3d04d5e10cc4e886aa450159 Mon Sep 17 00:00:00 2001 From: Exulansis Date: Wed, 17 Apr 2019 13:06:58 +0200 Subject: [PATCH 5/5] 2.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1234b09f..d40c5fc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jolocom-lib", - "version": "2.4.2", + "version": "2.4.3", "description": "Unified library for interacting with the Jolocom identity solution", "main": "js/index.js", "files": [