Skip to content

Commit

Permalink
Include email on server.getSession (bluesky-social#756)
Browse files Browse the repository at this point in the history
* include email on getSession

* fix up tests & return email on createSession

* fix more tests

* cleanup
  • Loading branch information
dholms authored Apr 4, 2023
1 parent ac905f3 commit 095652b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lexicons/com/atproto/server/getSession.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"required": ["handle", "did"],
"properties": {
"handle": {"type": "string", "format": "handle"},
"did": {"type": "string", "format": "did"}
"did": {"type": "string", "format": "did"},
"email": {"type": "string"}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,9 @@ export const schemaDict = {
type: 'string',
format: 'did',
},
email: {
type: 'string',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type InputSchema = undefined
export interface OutputSchema {
handle: string
did: string
email?: string
[k: string]: unknown
}

Expand Down
6 changes: 5 additions & 1 deletion packages/api/tests/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('agent', () => {
expect(sessionInfo).toEqual({
did: res.data.did,
handle: res.data.handle,
email: '[email protected]',
})

expect(events.length).toEqual(1)
Expand All @@ -72,9 +73,10 @@ describe('agent', () => {

const agent1 = new AtpAgent({ service: server.url, persistSession })

const email = '[email protected]'
await agent1.createAccount({
handle: 'user2.test',
email: '[email protected]',
email,
password: 'password',
})

Expand All @@ -95,6 +97,7 @@ describe('agent', () => {
expect(sessionInfo).toEqual({
did: res1.data.did,
handle: res1.data.handle,
email,
})

expect(events.length).toEqual(2)
Expand Down Expand Up @@ -136,6 +139,7 @@ describe('agent', () => {
expect(sessionInfo).toEqual({
did: res1.data.did,
handle: res1.data.handle,
email: res1.data.email,
})

expect(events.length).toEqual(2)
Expand Down
2 changes: 1 addition & 1 deletion packages/pds/src/api/com/atproto/server/getSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function (server: Server, ctx: AppContext) {
}
return {
encoding: 'application/json',
body: { handle: user.handle, did: user.did },
body: { handle: user.handle, did: user.did, email: user.email },
}
},
})
Expand Down
3 changes: 3 additions & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,9 @@ export const schemaDict = {
type: 'string',
format: 'did',
},
email: {
type: 'string',
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type InputSchema = undefined
export interface OutputSchema {
handle: string
did: string
email?: string
[k: string]: unknown
}

Expand Down
1 change: 1 addition & 0 deletions packages/pds/tests/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ describe('account', () => {
const res = await agent.api.com.atproto.server.getSession({})
expect(res.data.did).toBe(did)
expect(res.data.handle).toBe(handle)
expect(res.data.email).toBe(email)
})

const getMailFrom = async (promise): Promise<Mail.Options> => {
Expand Down
17 changes: 13 additions & 4 deletions packages/pds/tests/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ describe('auth', () => {
}

it('provides valid access and refresh token on account creation.', async () => {
const email = '[email protected]'
const account = await createAccount({
handle: 'alice.test',
email: '[email protected]',
email,
password: 'password',
})
// Valid access token
const sessionInfo = await getSession(account.accessJwt)
expect(sessionInfo).toEqual({ did: account.did, handle: account.handle })
expect(sessionInfo).toEqual({
did: account.did,
handle: account.handle,
email,
})
// Valid refresh token
const nextSession = await refreshSession(account.refreshJwt)
expect(nextSession).toEqual(
Expand All @@ -75,9 +80,10 @@ describe('auth', () => {
})

it('provides valid access and refresh token on session creation.', async () => {
const email = '[email protected]'
await createAccount({
handle: 'bob.test',
email: '[email protected]',
email,
password: 'password',
})
const session = await createSession({
Expand All @@ -89,6 +95,7 @@ describe('auth', () => {
expect(sessionInfo).toEqual({
did: session.did,
handle: session.handle,
email,
})
// Valid refresh token
const nextSession = await refreshSession(session.refreshJwt)
Expand Down Expand Up @@ -127,17 +134,19 @@ describe('auth', () => {
})

it('provides valid access and refresh token on session refresh.', async () => {
const email = '[email protected]'
const account = await createAccount({
handle: 'carol.test',
email: '[email protected]',
password: 'password',
email,
})
const session = await refreshSession(account.refreshJwt)
// Valid access token
const sessionInfo = await getSession(session.accessJwt)
expect(sessionInfo).toEqual({
did: session.did,
handle: session.handle,
email,
})
// Valid refresh token
const nextSession = await refreshSession(session.refreshJwt)
Expand Down

0 comments on commit 095652b

Please sign in to comment.