Skip to content

Commit b48b4a9

Browse files
committed
feat(pocket): Remove Pocket back-end code
Because: * Pocket will be decommissioned on Oct 8. FxA was asked to remove all Pocket references. This commit: * Removes our special casing Pocket code in our back-ends. Existing Pocket access tokens in mysql will need to be pruned separately closes FXA-12475
1 parent 4a5d267 commit b48b4a9

14 files changed

Lines changed: 11 additions & 290 deletions

File tree

packages/fxa-auth-server/config/dev.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@
188188
"dcdb5ae7add825d2": "123done",
189189
"5882386c6d801776": "firefox-desktop",
190190
"98e6508e88680e1a": "fxa-settings",
191-
"7377719276ad44ee": "pocket-mobile",
192-
"749818d3f2e7857f": "pocket-web",
193191
"8269bacd7bbc7f80": "thunderbird"
194192
},
195193
"clients": [

packages/fxa-auth-server/config/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,7 @@ const convictConf = convict({
504504
subscriptionSupportUrl: {
505505
doc: 'url to Mozilla subscription support page',
506506
format: String,
507-
default:
508-
'https://support.mozilla.org/products',
507+
default: 'https://support.mozilla.org/products',
509508
},
510509
redirectDomain: {
511510
doc: 'Domain that mail urls are allowed to redirect to',
@@ -1212,9 +1211,6 @@ const convictConf = convict({
12121211
},
12131212
},
12141213
clientIdToServiceNames: {
1215-
// This is used by oauth/db/index.js to identify pocket client ids so that it
1216-
// can store them separately in mysql.
1217-
// It's also used for amplitude stats
12181214
doc: 'Mappings from client id to service name: { "id1": "name-1", "id2": "name-2" }',
12191215
default: {},
12201216
format: 'Object',

packages/fxa-auth-server/lib/oauth/db/index.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ const REFRESH_LAST_USED_AT_UPDATE_AFTER_MS = config.get(
2424
'oauthServer.refreshToken.updateAfter'
2525
);
2626

27-
function getPocketIds(idNameMap) {
28-
return Object.entries(idNameMap)
29-
.filter(([_, name]) => name.startsWith('pocket'))
30-
.map(([id, _]) => id);
31-
}
32-
33-
const POCKET_IDS = getPocketIds(
34-
config.get('oauthServer.clientIdToServiceNames')
35-
);
36-
3727
class OauthDB extends ConnectedServicesDb {
3828
get mysql() {
3929
return this.db;
@@ -92,12 +82,6 @@ class OauthDB extends ConnectedServicesDb {
9282
// We avoid revocation concerns with short-lived
9383
// tokens, so we do not store them.
9484
return token;
95-
} else if (POCKET_IDS.includes(hex(vals.clientId))) {
96-
// Pocket tokens are persisted past their expiration for legacy
97-
// reasons: https://bugzilla.mozilla.org/show_bug.cgi?id=1547902
98-
// since they are long lived we continue to store them in mysql
99-
// so that redis can be exclusively ephemeral
100-
await this.mysql._generateAccessToken(token);
10185
} else {
10286
await this.redis.setAccessToken(token);
10387
}
@@ -217,10 +201,6 @@ class OauthDB extends ConnectedServicesDb {
217201
await this.mysql._removeTokensAndCodes(uid);
218202
}
219203

220-
getPocketIds() {
221-
return POCKET_IDS;
222-
}
223-
224204
async pruneAuthorizationCodes(ttlInMs) {
225205
return await this.mysql._pruneAuthorizationCodes(
226206
ttlInMs || config.get('oauthServer.expiration.code')

packages/fxa-auth-server/lib/oauth/db/mysql/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ const QUERY_DEVELOPER_DELETE =
123123
'LEFT JOIN clientDevelopers ON developers.developerId = clientDevelopers.developerId ' +
124124
'WHERE developers.email=?';
125125
// When listing access tokens, we deliberately do not exclude tokens that have expired.
126-
// Such tokens will be cleaned up by a background job, except for those belonging to Pocket, which might
127-
// one day come back to life as refresh tokens. (ref https://bugzilla.mozilla.org/show_bug.cgi?id=1547902).
126+
// Such tokens will be cleaned up by a background job.
128127
// There's minimal downside to showing tokens in the brief period between when they expire and when
129128
// they get deleted from the db.
130129
const QUERY_LIST_ACCESS_TOKENS_BY_UID =
@@ -539,14 +538,14 @@ class MysqlStore extends MysqlOAuthShared {
539538
}
540539

541540
_getRefreshToken(token) {
542-
return this._readOne(QUERY_REFRESH_TOKEN_FIND, [buf(token)]).then(function (
543-
t
544-
) {
545-
if (t) {
546-
t.scope = ScopeSet.fromString(t.scope);
541+
return this._readOne(QUERY_REFRESH_TOKEN_FIND, [buf(token)]).then(
542+
function (t) {
543+
if (t) {
544+
t.scope = ScopeSet.fromString(t.scope);
545+
}
546+
return t;
547547
}
548-
return t;
549-
});
548+
);
550549
}
551550

552551
_touchRefreshToken(token, now) {

packages/fxa-auth-server/lib/oauth/token.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,7 @@ exports.verify = async function verify(accessToken) {
6969
+token.expiresAt >=
7070
config.get('oauthServer.expiration.accessTokenExpiryEpoch');
7171

72-
// Pocket was one of FxA first clients and does not currently support refresh tokens.
73-
// We currently can't expire any pocket tokens.
74-
// Ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1547902
75-
const isPocket = db.getPocketIds().includes(token.clientId.toString('hex'));
76-
77-
if (expired && !isPocket) {
72+
if (expired) {
7873
throw OauthError.expiredToken(token.expiresAt);
7974
}
8075

packages/fxa-auth-server/test/oauth/api.js

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,61 +2795,6 @@ describe('#integration - /v1', function () {
27952795
assert.equal(res.result.errno, 115);
27962796
});
27972797

2798-
describe('expired tokens from pocket clients', () => {
2799-
const clientId = '749818d3f2e7857f';
2800-
let accessTokenExpiryEpoch;
2801-
2802-
before(async () => {
2803-
await Server.close();
2804-
accessTokenExpiryEpoch = config.get(
2805-
'oauthServer.expiration.accessTokenExpiryEpoch'
2806-
);
2807-
config.set('oauthServer.expiration.accessTokenExpiryEpoch', undefined);
2808-
Server = await testServer.start();
2809-
assert.isDefined(Server);
2810-
});
2811-
2812-
after(async () => {
2813-
await Server.close();
2814-
config.set(
2815-
'oauthServer.expiration.accessTokenExpiryEpoch',
2816-
accessTokenExpiryEpoch
2817-
);
2818-
Server = await testServer.start();
2819-
assert.isDefined(Server);
2820-
});
2821-
2822-
it('should not reject expired tokens from pocket clients', async function () {
2823-
let res = await newToken(
2824-
{
2825-
ttl: 1,
2826-
},
2827-
{
2828-
clientId,
2829-
}
2830-
);
2831-
2832-
assert.equal(res.statusCode, 200);
2833-
assertSecurityHeaders(res);
2834-
assert.equal(res.result.expires_in, 1);
2835-
2836-
sandbox.useFakeTimers({
2837-
now: Date.now() + 1000 * 60 * 60, // 1 hr in future
2838-
shouldAdvanceTime: true,
2839-
});
2840-
2841-
res = await Server.api.post({
2842-
url: '/verify',
2843-
payload: {
2844-
token: res.result.access_token,
2845-
},
2846-
});
2847-
2848-
assert.equal(res.statusCode, 200);
2849-
assertSecurityHeaders(res);
2850-
});
2851-
});
2852-
28532798
describe('response', function () {
28542799
it('should return the correct response', function () {
28552800
return newToken({ scope: 'profile' })

packages/fxa-auth-server/test/oauth/db/index.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -683,68 +683,4 @@ describe('#integration - db', function () {
683683
assert.notOk(await db.getAccessToken(tokenIdHash));
684684
});
685685
});
686-
687-
describe('Access Token storage', () => {
688-
describe('Pocket tokens', () => {
689-
const pocketId = buf('749818d3f2e7857f');
690-
const userId = buf(randomString(16));
691-
const tokenData = {
692-
clientId: pocketId,
693-
name: 'pocket',
694-
canGrant: false,
695-
publicClient: true,
696-
userId: userId,
697-
698-
scope: ScopeSet.fromArray(['no_scope']),
699-
};
700-
701-
it('stores them in mysql', async () => {
702-
const t = await db.generateAccessToken(tokenData);
703-
const mysql = await db.mysql;
704-
const tt = await mysql._getAccessToken(t.tokenId);
705-
await db.removeAccessToken(t);
706-
assert.equal(hex(tt.tokenId), hex(t.tokenId));
707-
});
708-
709-
it('retrieves them with getAccessToken', async () => {
710-
const t = await db.generateAccessToken(tokenData);
711-
const tt = await db.getAccessToken(t.tokenId);
712-
await db.removeAccessToken(t);
713-
assert.equal(hex(tt.tokenId), hex(t.tokenId));
714-
});
715-
716-
it('retrieves them with getAccessTokensByUid', async () => {
717-
const t = await db.generateAccessToken(tokenData);
718-
const tokens = await db.getAccessTokensByUid(userId);
719-
await db.removeAccessToken(t);
720-
assert.isArray(tokens);
721-
assert.lengthOf(tokens, 1);
722-
assert.deepEqual(tokens[0].tokenId, t.tokenId);
723-
assert.deepEqual(tokens[0].clientId, t.clientId);
724-
});
725-
726-
it('deletes them with removeAccessToken', async () => {
727-
const t = await db.generateAccessToken(tokenData);
728-
const tt = await db.getAccessToken(t.tokenId);
729-
await db.removeAccessToken(t);
730-
assert.isNotNull(tt);
731-
const ttt = await db.getAccessToken(t.tokenId);
732-
assert.isUndefined(ttt);
733-
});
734-
735-
it('deletes them with deleteClientAuthorization', async () => {
736-
const t = await db.generateAccessToken(tokenData);
737-
await db.deleteClientAuthorization(t.clientId, t.userId);
738-
const tt = await db.getAccessToken(t.tokenId);
739-
assert.isUndefined(tt);
740-
});
741-
742-
it('deletes them with removeTokensAndCodes', async () => {
743-
const t = await db.generateAccessToken(tokenData);
744-
await db.removeTokensAndCodes(t.userId);
745-
const tt = await db.getAccessToken(t.tokenId);
746-
assert.isUndefined(tt);
747-
});
748-
});
749-
});
750686
});

packages/fxa-event-broker/src/jwtset/jwtset.service.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,4 @@ export class JwtsetService {
123123
uid: delEvent.uid,
124124
});
125125
}
126-
127-
public generateAppleMigrationSET(
128-
appleMigrationEvent: set.appleMigrationEvent
129-
): Promise<string> {
130-
return this.generateSET({
131-
uid: appleMigrationEvent.uid,
132-
clientId: appleMigrationEvent.clientId,
133-
events: {
134-
[set.APPLE_USER_MIGRATION_ID]: {
135-
fxaEmail: appleMigrationEvent.fxaEmail,
136-
appleEmail: appleMigrationEvent.appleEmail,
137-
transferSub: appleMigrationEvent.transferSub,
138-
success: appleMigrationEvent.success,
139-
err: appleMigrationEvent.err,
140-
uid: appleMigrationEvent.uid,
141-
},
142-
},
143-
});
144-
}
145126
}

packages/fxa-event-broker/src/jwtset/set.interface.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export const PROFILE_EVENT_ID =
1111
'https://schemas.accounts.firefox.com/event/profile-change';
1212
export const SUBSCRIPTION_STATE_EVENT_ID =
1313
'https://schemas.accounts.firefox.com/event/subscription-state-change';
14-
export const APPLE_USER_MIGRATION_ID =
15-
'https://schemas.accounts.firefox.com/event/apple-user-migration';
1614

1715
export type deleteEvent = {
1816
clientId: string;
@@ -53,13 +51,3 @@ export type subscriptionEvent = {
5351
isActive: boolean;
5452
changeTime: number;
5553
};
56-
57-
export type appleMigrationEvent = {
58-
uid: string;
59-
clientId: string;
60-
fxaEmail: string;
61-
appleEmail: string;
62-
transferSub: string;
63-
success: boolean;
64-
err: string;
65-
};

packages/fxa-event-broker/src/pubsub-proxy/pubsub-proxy.controller.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,6 @@ export class PubsubProxyController {
195195
accountLocked: message.accountLocked,
196196
});
197197
}
198-
case dto.APPLE_USER_MIGRATION_EVENT: {
199-
return await this.jwtset.generateAppleMigrationSET({
200-
clientId,
201-
uid: message.uid,
202-
fxaEmail: message.fxaEmail,
203-
appleEmail: message.appleEmail,
204-
transferSub: message.transferSub,
205-
success: message.success,
206-
err: message.error,
207-
});
208-
}
209198
default:
210199
throw Error(`Invalid event: ${message.event}`);
211200
}

0 commit comments

Comments
 (0)