Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Authentication module #49

Merged
merged 10 commits into from
Sep 24, 2020
Merged

Authentication module #49

merged 10 commits into from
Sep 24, 2020

Conversation

javiesses
Copy link
Contributor

@javiesses javiesses commented Sep 17, 2020

  • Reducer
    • Reducer tests
  • Operations
    • Operations tests POC (are commented to prevent breaking CircleCI tests, they point to a local server)
    • Operations unit tests with mocked server

The base of the PR is #46 to make it easier to compare the changes, will be changed once that PR is merged

@ilanolkies ilanolkies added this to the v0.1 milestone Sep 17, 2020
@ilanolkies ilanolkies added the enhancement New feature or request label Sep 17, 2020
@javiesses javiesses marked this pull request as ready for review September 17, 2020 19:00
@javiesses javiesses changed the base branch from handle-credentials to develop September 17, 2020 19:02

export const serviceLoginFactory = (agent: Agent) => (serviceUrl: string, serviceDid: string, did: string, cb?: Callback<string>) => (dispatch: Dispatch) => callbackify(
async () => {
const makeLoginCredentialPayload = (challenge: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create this closure outside serviceLoginFactory closure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left them inside the serviceAuthenticationFactory because they depends on some variables that are received by the parent function. Do you think I should move them outside and send the needed params? I'm talking about did and serviceDid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can curry them

}
}

const verifyServiceDid = (message: Message): Credential => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return axios.post(`${serviceUrl}/request-auth`, { did })
.then(res => res.status === 200 && res.data)
.then(data => data.challenge)
.then(makeLoginCredentialPayload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should use credential model here or just a signed jwt? I think using just a jwt to respond here makes it simpler and it has the same effect, signing the challenge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I partially agree on that. It's true that it will become simpler to create just a signed JWT instead of a VC, but take in account that daf-w3c already has an action handler to build those VCs, and if we want to sign a JWT we should build an action handler to do that within daf-did-jwt because it is not created yet, or use directly did-jwt package with no agent involved, we just need to obtain the signer from it.
I think is cleaner to create a daf-did-jwt action handler inside rif-id-daf package

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another hand, if we change the type of the JWT we should change the auth package as well, it is expecting the challenge inside a W3C VC
https://github.com/rsksmart/rif-identity-services/blob/cc4b183b9dc3d60e958be1da87afeafb87aba9ad/rif-id-jwt-auth/src/index.js#L76-L78

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should build an action handler to do that within daf-did-jwt

that's a bummer...

I think is cleaner to create a daf-did-jwt action handler inside rif-id-daf package

I would rise an issue in uPort project to see if they are interested in merging this, what do you think?

we should change the auth package as well

IMHO it worths it


Anyway, before taking any desicion let's think a little bit better on this interface. I guess a good extension in the future will include some credentials in this step

  1. User requests access
  2. Services sends a token and a selective disclosure request
  3. User fills request with declarative details and/or presentations + challange
  4. Service grants access and gives credential to user, probably including metadata taken from the request response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what we already agreed, let's do the following:

  1. User requests access
  2. Service sends a challenge
  3. Users signs a VP with the received challenge in the VP metadata. The user should include the needed VC inside that VP, if the service does not require any VC, it should send an empty array
  4. Service validates the challenge and performs the needed business validations with the received VCs
  5. If all the validations pass, the service creates a VC and sends it JWT representation to the user
  6. User uses the received VC to authenticate each request to the service

Remarks:

  • Why the user needs to include VCs in the authentication process? Because the service may need to verify some business logic before granting access, for instance, that the user is older than 18 years old
  • Why the user will authenticate with the received VC and not with a ad hoc VP for each request? Because there is not added value by doing that and it needs an extra signing step with no sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a new issue in rif-identity-services

import { ActionSignW3cVc } from 'daf-w3c'
import { addServiceToken } from '../reducers/authentication'

export const serviceLoginFactory = (agent: Agent) => (serviceUrl: string, serviceDid: string, did: string, cb?: Callback<string>) => (dispatch: Dispatch) => callbackify(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the name “authenticate” instead of “login”, it describes better what this is doing. What do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Sounds better


await serviceLogin(serviceUrl, notServiceDid, identity.did)(store.dispatch).catch(e => {
expect(e.message).toEqual('The issuer of the auth credential is not the expected did')
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s test the state after the error is thrown. It should be same than before throwing. Adding issue to add it in this one and in the other operations tests

packages/rif-id-core/src/operations/authentication.ts Outdated Show resolved Hide resolved
packages/rif-id-core/src/operations/authentication.ts Outdated Show resolved Hide resolved
packages/rif-id-core/src/operations/authentication.ts Outdated Show resolved Hide resolved
@javiesses javiesses force-pushed the auth-module branch 2 times, most recently from 123f73f to 6c097d6 Compare September 23, 2020 14:23
@ilanolkies ilanolkies merged commit 216f1cc into develop Sep 24, 2020
@delete-merged-branch delete-merged-branch bot deleted the auth-module branch September 24, 2020 16:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants