Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-18165 cla: add GitHub login #4244

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrAuth.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as cldrClient from "../esm/cldrClient.mjs";
import * as cldrStatus from "../esm/cldrStatus.mjs";

/**
* Get the oauth login URL
* @param {object} o options bag
* @param {string} o.service which service, currently only 'github' is accepted
* @param {string} o.intent what the login URL is used for, currently only 'cla'
* @param {boolean} o.relogin if true, attempt re-login
*/
export async function getLoginUrl(o) {
const { service, intent, relogin } = o;
if (service !== "github")
throw Error(`only support service='github' but got ${service}`);
if (intent !== "cla")
throw Error(`only support intent='cla' but got ${intent}`);
const client = await cldrClient.getClient();
const { url } = (await client.apis.auth.oauthUrl()).body;
const u = new URL(url);
// TODO: may move this into the GithubLoginFactory#getLoginUrl()
srl295 marked this conversation as resolved.
Show resolved Hide resolved
const redir = new URL(window.location);
redir.search = "";
redir.hash = "";
redir.pathname = cldrStatus.getContextPath() + "/github-login";
u.searchParams.set("redirect_uri", redir);
if (relogin) {
u.searchParams.set("prompt", "select_account");
}
return u;
}

/**
* If a valid github ID is in the session, return it, otherwise falsy
* @returns github ID or falsy
*/
export async function getGithubIdFromSession() {
try {
const client = await cldrClient.getClient();
const { id } = (await client.apis.auth.oauthSession()).body;
return id;
} catch (e) {
console.error(e);
console.error("getGithubIdFromSession() failed");
}
return null;
}
4 changes: 4 additions & 0 deletions tools/cldr-apps/js/src/esm/cldrComponents.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Button,
Card,
Checkbox,
Col,
Collapse,
CollapsePanel,
Form,
Expand All @@ -33,6 +34,7 @@ import {
Popover,
Progress,
Radio,
Row,
Select,
Spin,
Steps,
Expand Down Expand Up @@ -62,6 +64,7 @@ function setup(app) {
app.component("a-button", Button);
app.component("a-card", Card);
app.component("a-checkbox", Checkbox);
app.component("a-col", Col);
app.component("a-collapse-panel", CollapsePanel);
app.component("a-collapse", Collapse);
app.component("a-form-item", Form.Item);
Expand All @@ -77,6 +80,7 @@ function setup(app) {
app.component("a-progress", Progress);
app.component("a-radio-group", Radio.Group);
app.component("a-radio", Radio);
app.component("a-row", Row);
app.component("a-select", Select);
app.component("a-spin", Spin);
app.component("a-step", Steps.Step);
Expand Down
6 changes: 4 additions & 2 deletions tools/cldr-apps/js/src/views/MainMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<li>
<ul>
<li><a href="#account///">Account Settings</a></li>
<li v-if="showClaMenu"><a href="#cla///">Sign CLA</a></li>
<li v-if="showClaMenu">
<a href="#cla///">CLA (Contributor License Agreement) Status</a>
</li>
</ul>
</li>
<li v-if="!isAdmin && !accountLocked">
Expand Down Expand Up @@ -155,7 +157,7 @@ export default {
recentActivityUrl: null,
uploadXmlUrl: null,
userId: 0,
showClaMenu: false, // off by default, see CLDR-16499
showClaMenu: true,
};
},

Expand Down
Loading
Loading