Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Feedback from Aurel #114

Merged
merged 32 commits into from
Sep 23, 2024
Merged

API Feedback from Aurel #114

merged 32 commits into from
Sep 23, 2024

Conversation

tahpot
Copy link
Member

@tahpot tahpot commented Sep 13, 2024

@tahpot tahpot self-assigned this Sep 13, 2024
@aurelticot aurelticot marked this pull request as draft September 16, 2024 01:21
@aurelticot
Copy link
Member

@tahpot let me know when the PR is ready for review. I see you're adding a few more things

@aurelticot aurelticot linked an issue Sep 17, 2024 that may be closed by this pull request
@tahpot
Copy link
Member Author

tahpot commented Sep 17, 2024

Note: This refactor has made a lot of breaking changes.

You will need to disconnect any existing connections you have and then re-create them before using this branch.

Copy link
Member

@aurelticot aurelticot left a comment

Choose a reason for hiding this comment

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

See inline comments


Additionally, I was unable to connect to Google while testing with the embedded web dev UI.

Got the following error:

Screenshot 2024-09-18 at 12 47 40 PM

It refers to:

const account = new AutoAccount({
privateKey: contextSignature,
network: VERIDA_ENVIRONMENT,
// @ts-ignore
didClientConfig: DID_CLIENT_CONFIG
})

The network and DID client config come from my serverconfig.local.json whic seem correct.

The contextSignature is passed when calling Utils.getNetwork in the `callback controller function.

public static async callback(req: UniqueRequest, res: Response, next: any) {
logger.trace('callback()')
const providerName = req.params.provider
const provider = Providers(providerName)
try {
const connectionResponse = await provider.callback(req, res, next)
const did = req.session.did
const key = req.session.key
const redirect = req.session.redirect
const networkInstance = await Utils.getNetwork(key, req.requestId)

The key comes from the session, this may be the missing element

src/providers/routes.ts Outdated Show resolved Hide resolved
src/providers/controller.ts Outdated Show resolved Hide resolved
src/providers/controller.ts Outdated Show resolved Hide resolved
src/providers/twitter/index.ts Show resolved Hide resolved
src/api/rest/v1/providers/controller.ts Outdated Show resolved Hide resolved
src/api/rest/v1/providers/controller.ts Outdated Show resolved Hide resolved
src/api/rest/v1/providers/controller.ts Outdated Show resolved Hide resolved
src/api/rest/v1/providers/controller.ts Outdated Show resolved Hide resolved
src/api/rest/v1/connections/routes.ts Outdated Show resolved Hide resolved
src/api/rest/v1/connections/controller.ts Show resolved Hide resolved
@tahpot
Copy link
Member Author

tahpot commented Sep 18, 2024

See inline comments

Additionally, I was unable to connect to Google while testing with the embedded web dev UI.

Got the following error:

Screenshot 2024-09-18 at 12 47 40 PM

It refers to:

const account = new AutoAccount({
privateKey: contextSignature,
network: VERIDA_ENVIRONMENT,
// @ts-ignore
didClientConfig: DID_CLIENT_CONFIG
})

The network and DID client config come from my serverconfig.local.json whic seem correct.

The contextSignature is passed when calling Utils.getNetwork in the `callback controller function.

public static async callback(req: UniqueRequest, res: Response, next: any) {
logger.trace('callback()')
const providerName = req.params.provider
const provider = Providers(providerName)
try {
const connectionResponse = await provider.callback(req, res, next)
const did = req.session.did
const key = req.session.key
const redirect = req.session.redirect
const networkInstance = await Utils.getNetwork(key, req.requestId)

The key comes from the session, this may be the missing element

I had this issue as well. There's a bug in the UI where entering the private key for the first time in the connection screen doesn't work. Enter the private key, then reload the page, then try to connect.

@aurelticot
Copy link
Member

I had this issue as well. There's a bug in the UI where entering the private key for the first time in the connection screen doesn't work. Enter the private key, then reload the page, then try to connect.

Ok.
I was about to comment tohat I don't have this issue in the Vault web when using this branch for the server, so yes it comes from the embedded dev web UI.

Copy link
Member

@aurelticot aurelticot left a comment

Choose a reason for hiding this comment

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

Just did a static review. I'm starting the server and updating the Vault to actually test it.

I resolved the inline comments from the previous review except for a couple for which I added new comments for you

Copy link
Member

@aurelticot aurelticot left a comment

Choose a reason for hiding this comment

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

Got another issue with the readableId of the profile.

When connecting a new account, once in the callback controller, it calls the specific callback of the provider:

const connectionResponse = await provider.callback(req, res, next)

In the case of Google, it sets the profile with the username and readableId using the email.

profile: {
username: data.profile.email,
readableId: data.profile.email,
...data.profile,
}
};

Back in the callback controller, it eventually saveProvider (should actually be called saveNewConnection to be more relevant)

const connection = await syncManager.saveProvider(providerId, connectionResponse.accessToken, connectionResponse.refreshToken, connectionResponse.profile)

This function redefined the profile and overwrite whatever was in readableId and forget to include username:

const connectionProfile: ConnectionProfile = {
id: profile.id,
name: profile.displayName,
avatar: {
uri: profile.photos && profile.photos.length ? profile.photos[0].value : undefined
},
readableId: `${profile.displayName} (${profile.id})`,
//uri:
givenName: profile.name.givenName,
familyName: profile.name.familyName,
email: profile.emails && profile.emails.length ? profile.emails[0].value : undefined,
...(profile.connectionProfile ? profile.connectionProfile : {})
}

It can be easily fixed with the following (but also requires fixing the types of the profile):

const connectionProfile: ConnectionProfile = {
            id: profile.id,
            name: profile.displayName,
            avatar: {
                uri: profile.photos && profile.photos.length ? profile.photos[0].value : undefined
            },
            readableId: profile.readableId || `${profile.displayName} (${profile.id})`,
            username: profile.username,
            givenName: profile.name.givenName,
            familyName: profile.name.familyName,
            email: profile.emails && profile.emails.length ? profile.emails[0].value : undefined,
            ...(profile.connectionProfile ? profile.connectionProfile : {})
        }

Back to Google: data.profile.email doesn't exist in the Passport profile, it's data.profile.emails, hence the importance of typing passport properly, it would have been caught.

@tahpot
Copy link
Member Author

tahpot commented Sep 23, 2024

Back to Google: data.profile.email doesn't exist in the Passport profile, it's data.profile.emails, hence the importance of typing passport properly, it would have been caught.

Should be fixed with: 218a7d8

@tahpot
Copy link
Member Author

tahpot commented Sep 23, 2024

Back in the callback controller, it eventually saveProvider (should actually be called saveNewConnection to be more relevant)

Fixed.

It can be easily fixed with the following (but also requires fixing the types of the profile)

Should also be fixed.

See 3007d70

Copy link
Member

@aurelticot aurelticot left a comment

Choose a reason for hiding this comment

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

All good. Thanks

@tahpot tahpot merged commit 91a1aea into develop Sep 23, 2024
2 checks passed
@tahpot tahpot deleted the feature/api-feedback-sept-24 branch September 23, 2024 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment