Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Notify push and email on code exchanges #2985

Merged
merged 1 commit into from
Apr 1, 2019
Merged

Conversation

vladikoff
Copy link
Contributor

Fixes #2880
Fixes #2955

@@ -114,7 +114,7 @@ module.exports = (log, db, push) => {
deviceName = synthesizeName(deviceInfo)
}
if (credentials.tokenVerified) {
request.app.devices.then(devices => {
db.devices(credentials.uid).then(devices => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this needed? I wonder if we can find a way to fix request.app.devices so that we maintain the nice caching behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lib/routes/oauth.js Outdated Show resolved Hide resolved

const tokenVerify = await oauthdb.checkAccessToken({
token: grant.access_token
})
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like a bit of a code smell that you have to check the access_token here immediately after generating it; is this so that you can find out the uid in the grant_type=authorization_code case? I wonder if we could arrange for the oauth-server to return that information directly from /token rather than having to verify it again here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that would be nice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rfk how about we leave this as a follow up for now? merge with the checkAccessToken then optimize by landing #3000 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, works for me.


module.exports = (config) => {
return {
path: '/v1/verify',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get rid of this, /token endpoint can provide the uid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fxa-uid field

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 #3000

lib/routes/utils/oauth.js Outdated Show resolved Hide resolved
lib/routes/utils/oauth.js Outdated Show resolved Hide resolved
lib/routes/utils/oauth.js Outdated Show resolved Hide resolved
lib/routes/utils/oauth.js Outdated Show resolved Hide resolved
}

const account = await db.account(uid)
await mailer.sendNewDeviceLoginNotification(account.emails, account, emailOptions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

might have emails on sessionToken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, no emails on sessionToken, just one email.

@vladikoff vladikoff force-pushed the fenix-token-exchanges branch 2 times, most recently from dc9bfa8 to 4bb82c1 Compare March 28, 2019 03:25
@vladikoff vladikoff marked this pull request as ready for review March 30, 2019 19:14
@vladikoff vladikoff requested a review from rfk March 30, 2019 19:15
@vladikoff vladikoff changed the title [WIP] Notify push and email on code exchanges Notify push and email on code exchanges Mar 30, 2019
Copy link
Contributor

@rfk rfk left a comment

Choose a reason for hiding this comment

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

Thanks @vladikoff, this looks good except for the return of the refreshToken-vs-refreshTokenId issue.


if (! credentials.refreshTokenId) {
// provide a refreshToken for the device creation below
credentials.refreshTokenId = grant.refresh_token;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is mixing up refresh_token and refresh_token_id (that is, the unhashed and the hashed variants). You'll need to either hash refresh_token yourself here, or return an additional fxa-refreshTokenId field in the /token 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.

oh classic ... , updated , also updated the test


// we set tokenVerified because the granted scope is part of NOTIFICATION_SCOPES
credentials.tokenVerified = true;
credentials.client = await oauthdb.getClientInfo(clientId);
Copy link
Contributor

Choose a reason for hiding this comment

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

We ought to be able to do a cached lookup here, but not for this PR; I filed https://github.com/mozilla/fxa-auth-server/issues/3006 as a followup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

lib/routes/utils/oauth.js Outdated Show resolved Hide resolved
test/client/api.js Outdated Show resolved Hide resolved

'use strict';

const encrypt = require('../../../fxa-oauth-server/lib/encrypt');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to be OK at runtime in the docker images we build for production? I wonder if it would be less risky to just copy the code over here, it's only 3 lines worth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah! we have the technology!

Copy link
Contributor

@rfk rfk left a comment

Choose a reason for hiding this comment

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

Looks like the dockerfile does in fact include the fxa-oauth-server subdirectory when building, so 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants