Skip to content

Commit fee65f9

Browse files
Revert "feat(cognito): verify SSO users and migrate"
This reverts commit 1b2e606, 96e30ad, 921b001, 0693cd5, 9afaa9a
1 parent 96e30ad commit fee65f9

File tree

8 files changed

+54
-2206
lines changed

8 files changed

+54
-2206
lines changed

examples/javascript/src/lib/api-service.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ const makeRequest = async (options) => {
3535

3636
const url = new URL(options.path, apiUrl);
3737

38-
console.log("@@url: ", url)
39-
console.log("@@request: ", {
40-
url: url.toString(),
41-
method: options.method || 'get',
42-
headers: {...headers, 'Authorization': `Bearer ${options.token}`},
43-
data: options.body
44-
})
45-
4638
try {
4739
const response = await request({
4840
validateStatus: validStatus,

examples/javascript/src/lib/jane-service.mjs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -124,46 +124,6 @@ const verifyCredentials = async (data, token) => {
124124
return result
125125
}
126126

127-
/** ----- GET SSO USER ATTRIBUTES ----- */
128-
129-
const verifySSOUser = async (data, token) => {
130-
console.log("token: ", token)
131-
console.log("data: ", data)
132-
const parsedData = {
133-
...data,
134-
user_attributes: {
135-
...data.user_attributes,
136-
identities: JSON.parse(data.user_attributes.identities)
137-
}
138-
}
139-
const response = await apiService.post(
140-
`${COGNITO_API}/verify_sso_user`,
141-
parsedData,
142-
token
143-
)
144-
145-
console.log("response: ", response)
146-
const result = {
147-
errorMessage: "",
148-
user: response.body?.user,
149-
}
150-
151-
switch (response.statusCode) {
152-
case 200:
153-
break
154-
case 404:
155-
result.errorMessage = "User not found"
156-
break
157-
default:
158-
result.errorMessage = buildErrorMessage(
159-
"Error verifying SSO user",
160-
response
161-
)
162-
}
163-
164-
return result
165-
}
166-
167127
/** ----- VALIDATE USER ----- */
168128

169129

@@ -211,6 +171,5 @@ export default {
211171
userExists,
212172
ensureExternalUserExists,
213173
verifyCredentials,
214-
verifySSOUser,
215174
validateUser
216175
}

examples/javascript/src/lib/utils.mjs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,3 @@ export const mapUserAttributes = (userAttributes) => {
4444

4545
return userData
4646
}
47-
48-
export const addAreaCodeToPhone = (phone) => {
49-
let partial = phone.startsWith("+") ? phone.substring(1) : phone
50-
51-
// Missing + and country code, 2223334444
52-
if (phone.length === 10) {
53-
return `+1${partial}`
54-
}
55-
56-
// If was already correct, just return the +
57-
return `+${partial}`
58-
}

examples/javascript/src/migration-lambda/index.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { addAreaCodeToPhone } from '../lib/utils.mjs';
21
import Jane from "../lib/jane-service.mjs";
32
import apiService from "../lib/api-service.mjs";
43

@@ -97,3 +96,15 @@ export const handler = async (event) => {
9796

9897
return event;
9998
};
99+
100+
const addAreaCodeToPhone = (phone) => {
101+
let partial = phone.startsWith("+") ? phone.substring(1) : phone;
102+
103+
// Missing + and country code, 2223334444
104+
if (phone.length === 10) {
105+
return `+1${partial}`;
106+
}
107+
108+
// If was already correct, just return the +
109+
return `+${partial}`;
110+
};
Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { addAreaCodeToPhone, mapUserAttributes } from "../lib/utils.mjs"
2-
import Jane from "../lib/jane-service.mjs"
3-
import apiService from "../lib/api-service.mjs"
4-
import {
5-
AdminUpdateUserAttributesCommand,
6-
CognitoIdentityProviderClient,
7-
} from "@aws-sdk/client-cognito-identity-provider"
1+
import { mapUserAttributes } from '../lib/utils.mjs';
2+
import Jane from '../lib/jane-service.mjs';
3+
import apiService from '../lib/api-service.mjs';
84

95
/**
106
* Possible trigger sources:
@@ -29,8 +25,6 @@ export const handler = async (event) => {
2925
);
3026
return event;
3127
}
32-
33-
event = await handleUserMigration(event, token);
3428

3529
const { success, errorMessage } = await Jane.createUser({
3630
pool_id: event.userPoolId,
@@ -47,85 +41,3 @@ export const handler = async (event) => {
4741

4842
return event;
4943
};
50-
/* Cognito SSO flows do not go through our migration handler
51-
instead we handle those migrations here, after signup.
52-
If a user is signing up via sso, we check for a Jane SSO user
53-
associated with this client and use that users data for the migration */
54-
const handleUserMigration = async (event, token) => {
55-
let userIdentities;
56-
try {
57-
userIdentities = JSON.parse(event.request.userAttributes.identities);
58-
} catch (err) {
59-
console.error("userIdentities unable to parse", err);
60-
return event;
61-
}
62-
63-
const userGoogleIdentity = userIdentities.find(
64-
(i) => i.providerType === "Google"
65-
);
66-
if (!userGoogleIdentity) {
67-
return event;
68-
}
69-
70-
const { errorMessage, user } = await Jane.verifySSOUser({
71-
email: event.request.userAttributes.email,
72-
user_attributes: event.request.userAttributes,
73-
app_client_id: event.callerContext.clientId,
74-
}, token);
75-
if (errorMessage === "User not found") {
76-
// Jane user for this client was not found, continue normal sign up
77-
return event;
78-
} else if (errorMessage || !user) {
79-
// something went wrong, continue normal sign up and log error
80-
console.error(`failed to retrieve data for migration: ${errorMessage}`);
81-
return event;
82-
}
83-
const attributes = {};
84-
const { first_name, last_name, phone, birth_date } = user;
85-
86-
const attributesToUpdate = [];
87-
first_name &&
88-
(attributes.given_name = first_name) &&
89-
attributesToUpdate.push({
90-
Name: "given_name",
91-
Value: first_name,
92-
});
93-
last_name &&
94-
(attributes.family_name = last_name) &&
95-
attributesToUpdate.push({
96-
Name: "family_name",
97-
Value: last_name,
98-
});
99-
phone &&
100-
(attributes.phone_number = addAreaCodeToPhone(phone)) &&
101-
attributesToUpdate.push({
102-
Name: "phone_number",
103-
Value: addAreaCodeToPhone(phone),
104-
});
105-
birth_date &&
106-
(attributes.birthdate = birth_date) &&
107-
attributesToUpdate.push({
108-
Name: "birthdate",
109-
Value: birth_date,
110-
});
111-
const cognitoIdServiceProvider = new CognitoIdentityProviderClient({
112-
region: "us-east-1",
113-
});
114-
const command = new AdminUpdateUserAttributesCommand({
115-
UserAttributes: attributesToUpdate,
116-
UserPoolId: event.userPoolId,
117-
Username: event.userName,
118-
});
119-
await cognitoIdServiceProvider
120-
.send(command)
121-
.then((data) => console.log("Cognito user updated!", data))
122-
.catch((err) => {
123-
console.error("Cognito Attribute Update Unsuccessful", err);
124-
});
125-
126-
event.request.userAttributes = {
127-
...event.request.userAttributes,
128-
...attributes,
129-
};
130-
return event;
131-
};

examples/javascript/src/pre-signup-lambda/index.mjs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ export const handler = async (event) => {
6060
}
6161

6262
if (userExists) {
63-
// Caveat, flow is "wrong" because SSO is sinup/sign in is the same thing, so it calls signup when
64-
// we actually want is signin
65-
66-
// Eg:
67-
// Here we should check event.triggerSource === 'PreSignUp_ExternalProvider'
68-
// User should be confirmed (just like a migration)
69-
// No message to user since it already had an account before (just like a migration)
70-
// And move flow along to Post-Confirmation, where it can finish the migration
71-
if (event.triggerSource === 'PreSignUp_ExternalProvider') {
72-
event.response.autoConfirmUser = true
73-
event.response.autoVerifyEmail = true
74-
75-
return event
76-
}
7763
throw Error('User already exists, please log in')
7864
}
7965

0 commit comments

Comments
 (0)