mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
[github-auth-provider] Prefer pass list email over primary email
This commit is contained in:
parent
be192ca1cb
commit
42ee644f98
@ -78,7 +78,7 @@ export class GitHubAuthProvider extends GenericAuthProvider {
|
|||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
const fetchPrimaryEmail = async () => {
|
const fetchUserEmails = async () => {
|
||||||
const response = await api.users.listEmails({});
|
const response = await api.users.listEmails({});
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw new GitHubApiError(response);
|
throw new GitHubApiError(response);
|
||||||
@ -86,7 +86,7 @@ export class GitHubAuthProvider extends GenericAuthProvider {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
const currentUserPromise = this.retry(() => fetchCurrentUser());
|
const currentUserPromise = this.retry(() => fetchCurrentUser());
|
||||||
const userEmailsPromise = this.retry(() => fetchPrimaryEmail());
|
const userEmailsPromise = this.retry(() => fetchUserEmails());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [ { data: { id, login, avatar_url, name }, headers }, userEmails ] = await Promise.all([ currentUserPromise, userEmailsPromise ]);
|
const [ { data: { id, login, avatar_url, name }, headers }, userEmails ] = await Promise.all([ currentUserPromise, userEmailsPromise ]);
|
||||||
@ -98,13 +98,26 @@ export class GitHubAuthProvider extends GenericAuthProvider {
|
|||||||
.map((s: string) => s.trim())
|
.map((s: string) => s.trim())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const filterPrimaryEmail = (emails: GitHub.UsersListEmailsResponse) => {
|
||||||
|
if (this.env.blockNewUsers) {
|
||||||
|
// if there is any verified email with a domain that is in the blockNewUsersPassList then use this email as primary email
|
||||||
|
const emailDomainInPasslist = (mail: string) => this.env.blockNewUsersPassList.some(e => mail.endsWith(`@${e}`));
|
||||||
|
const result = emails.filter(e => e.verified).filter(e => emailDomainInPasslist(e.email))
|
||||||
|
if (result.length > 0) {
|
||||||
|
return result[0].email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// otherwise use GitHub's primary email as Gitpod's primary email
|
||||||
|
return emails.filter(e => e.primary)[0].email;
|
||||||
|
};
|
||||||
|
|
||||||
return <AuthUserSetup>{
|
return <AuthUserSetup>{
|
||||||
authUser: {
|
authUser: {
|
||||||
authId: String(id),
|
authId: String(id),
|
||||||
authName: login,
|
authName: login,
|
||||||
avatarUrl: avatar_url,
|
avatarUrl: avatar_url,
|
||||||
name,
|
name,
|
||||||
primaryEmail: userEmails.filter(e => e.primary)[0].email
|
primaryEmail: filterPrimaryEmail(userEmails)
|
||||||
},
|
},
|
||||||
currentScopes
|
currentScopes
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user