Skip to content

Commit

Permalink
feat: remove username from payload and userdata
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This change REMOVES the `username` attribute from auth token payloads and therefore also from userData in @stacks/connect. Hence, there is NO MORE username verification done by @stacks/connect automatically.
  • Loading branch information
janniks committed Apr 19, 2022
1 parent e2f3cf9 commit 926c549
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 19 deletions.
3 changes: 0 additions & 3 deletions packages/auth/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export async function decryptPrivateKey(
* @param {String} privateKey the identity key of the Blockstack ID generating
* the authentication response
* @param {Object} profile the profile object for the Blockstack ID
* @param {String} username the username of the Blockstack ID if any, otherwise `null`
* @param {AuthMetadata} metadata an object containing metadata sent as part of the authentication
* response including `email` if requested and available and a URL to the profile
* @param {String} coreToken core session token when responding to a legacy auth request
Expand All @@ -181,7 +180,6 @@ export async function makeAuthResponse(
privateKey: string,
// eslint-disable-next-line @typescript-eslint/ban-types
profile: {} = {},
username: string | null = null,
metadata: AuthMetadata | null,
coreToken: string | null = null,
appPrivateKey: string | null = null,
Expand Down Expand Up @@ -232,7 +230,6 @@ export async function makeAuthResponse(
public_keys: [publicKey],
appPrivateKeyFromWalletSalt,
profile,
username,
core_token: coreTokenPayload,
},
additionalProperties
Expand Down
2 changes: 0 additions & 2 deletions packages/auth/src/userData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Returned from the [[UserSession.loadUserData]] function.
*/
export interface UserData {
// public: the blockstack ID (for example: stackerson.id or alice.blockstack.id)
username: string;
// public: the email address for the user. only available if the `email`
// scope is requested, and if the user has entered a valid email into
// their profile.
Expand Down
1 change: 0 additions & 1 deletion packages/auth/src/userSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ export class UserSession {
}

const userData: UserData = {
username: tokenPayload.username as string,
profile: tokenPayload.profile,
email: tokenPayload.email as string,
decentralizedID: tokenPayload.iss,
Expand Down
16 changes: 5 additions & 11 deletions packages/auth/tests/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ test('invalid auth request - invalid manifest uri', async () => {
});

test('makeAuthResponse && verifyAuthResponse', async () => {
const authResponse = await makeAuthResponse(privateKey, sampleProfiles.ryan, null, null);
const authResponse = await makeAuthResponse(privateKey, sampleProfiles.ryan, null);
expect(authResponse).toBeTruthy();

const decodedToken = decodeToken(authResponse);
Expand All @@ -179,7 +179,9 @@ test('makeAuthResponse && verifyAuthResponse', async () => {
expect(JSON.stringify((decodedToken.payload as any).profile)).toEqual(
JSON.stringify(sampleProfiles.ryan)
);
expect((decodedToken.payload as any).username).toBe(null);

// username was removed from payload
expect('username' in (decodedToken.payload as any)).toBeFalsy();

await verifyAuthResponse(authResponse).then(verifiedResult => {
expect(verifiedResult).toBe(true);
Expand All @@ -199,7 +201,6 @@ test('auth response with invalid or empty appPrivateKeyFromWalletSalt', async ()
null,
null,
null,
null,
undefined,
null,
null,
Expand All @@ -223,7 +224,6 @@ test('auth response with valid appPrivateKeyFromWalletSalt', async () => {
null,
null,
null,
null,
undefined,
null,
null,
Expand All @@ -245,7 +245,7 @@ test('auth response with valid appPrivateKeyFromWalletSalt', async () => {
test('auth response with username', async () => {
fetchMock.mockResponse(JSON.stringify(sampleNameRecords.ryan));

const authResponse = await makeAuthResponse(privateKey, sampleProfiles.ryan, 'ryan.id', null);
const authResponse = await makeAuthResponse(privateKey, sampleProfiles.ryan, null);

await verifyAuthResponse(authResponse).then(verifiedResult => {
expect(verifiedResult).toBe(true);
Expand All @@ -270,7 +270,6 @@ test('auth response with invalid private key', async () => {
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down Expand Up @@ -312,7 +311,6 @@ test('handlePendingSignIn with authResponseToken', async () => {
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down Expand Up @@ -340,7 +338,6 @@ test('handlePendingSignIn 2', async () => {
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down Expand Up @@ -387,7 +384,6 @@ test('handlePendingSignIn with existing user session', async () => {
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down Expand Up @@ -453,7 +449,6 @@ test('handlePendingSignIn with authResponseToken, transit key and custom Blockst
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down Expand Up @@ -503,7 +498,6 @@ test(
const authResponse = await makeAuthResponse(
privateKey,
sampleProfiles.ryan,
'ryan.id',
metadata,
undefined,
appPrivateKey,
Expand Down
1 change: 0 additions & 1 deletion packages/keychain/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export class Identity implements IdentifyInterface {
...(this.profile || {}),
stxAddress,
},
this.defaultUsername || '',
{
profileUrl,
},
Expand Down
1 change: 0 additions & 1 deletion packages/wallet-sdk/src/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const makeAuthResponse = async ({
mainnet: getStxAddress({ account, transactionVersion: TransactionVersion.Mainnet }),
},
},
account.username || '',
{
profileUrl,
},
Expand Down

0 comments on commit 926c549

Please sign in to comment.