-
Notifications
You must be signed in to change notification settings - Fork 0
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
add basic code to generate the login button #2
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1dcaffe
add basic code to generate the login button
gumaerc 0cbfa0e
add basic gitignore
gumaerc 1f1f60f
add basic linting and formatting config
gumaerc bcd0e19
add basic github actions ci config
gumaerc 04ab6f7
fix linter config issues
gumaerc 6b52cdc
fmt
gumaerc 72b287d
remove manual formatting and use pre-commit prettier instead
gumaerc c57619c
add missing typescript packages
gumaerc 1f03d55
use URL.origin
gumaerc aeeef19
add .nvmrc specifying v20
gumaerc e14a4d8
update yarn configuration
gumaerc 74b69c8
corepack fix for github actions
gumaerc f7d54cf
add back in package.json config removed by yarn init and lint
gumaerc 8358731
linting weirdness
gumaerc f6035f8
remove unnecessary packages
gumaerc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{js,json,yml}] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "eslint-config-mitodl", | ||
"env": { | ||
"browser": true, | ||
"jquery": true, | ||
"jest": true | ||
}, | ||
"globals": { | ||
"RELEASE_VERSION": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.yarn/** linguist-vendored | ||
/.yarn/releases/* binary | ||
/.yarn/plugins/**/* binary | ||
/.pnp.* binary linguist-generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: CI | ||
on: [push] | ||
|
||
jobs: | ||
javascript-tests: | ||
runs-on: ubuntu-latest | ||
env: | ||
SKIP_YARN_COREPACK_CHECK: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.8.1 | ||
cache: "yarn" | ||
|
||
- run: corepack enable | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Lint | ||
run: yarn lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Local Environment Settings | ||
.pydevproject | ||
.settings | ||
.project | ||
.idea/ | ||
.python-version | ||
.vscode/settings.json | ||
|
||
# A place to stick your files | ||
private/* | ||
|
||
# Autogenerated files | ||
*.DS_Store | ||
*~ | ||
*.pem | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
public/ | ||
node_modules | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
|
||
# webpack bundle analysis | ||
stats.json | ||
|
||
tsconfig.tsbuildinfo | ||
|
||
# Yarn stuff https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
ci: | ||
skip: | ||
- eslint | ||
repos: | ||
- repo: [email protected]:Yelp/detect-secrets | ||
rev: v1.3.0 | ||
hooks: | ||
- id: detect-secrets | ||
- id: detect-secrets | ||
args: | ||
- --baseline | ||
- .secrets.baseline | ||
- --exclude-files | ||
- README.md | ||
exclude: .*_test.*|yarn\.lock | ||
- --exclude-files | ||
- .yarn/ | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v3.1.0 | ||
hooks: | ||
- id: prettier | ||
types_or: | ||
[javascript, jsx, ts, tsx, json, scss, sass, css, yaml, markdown] | ||
args: | ||
- --no-config | ||
- --no-semi | ||
exclude: "(node_modules/|.yarn/)" |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.0.2.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Generates a simple HTML login button pointing an an instance of MIT Open | ||
* If already logged in, displays the user's username | ||
* @function initLoginButton | ||
* @param {String} containerId The id property of the container element to place the login button / status in | ||
* @param {String} baseUrl The base URL of the MIT Open instance | ||
* @param {String} buttonText The text to show on the Login button | ||
* @param {String} buttonClass The CSS class(es) to assign to the button | ||
* @param {String} loggedInTextClass The CSS class(es) to assign to the logged-in status text | ||
*/ | ||
export function initLoginButton( | ||
containerId, | ||
baseUrl, | ||
buttonText = "Login", | ||
buttonClass = "", | ||
loggedInTextClass = "", | ||
) { | ||
const container = document.getElementById(containerId) | ||
const parsedBaseUrl = new URL(baseUrl) | ||
const apiUrl = `${parsedBaseUrl.origin}/api/v0/users/me?format=json` | ||
const loginUrl = `${parsedBaseUrl.origin}/login/ol-oidc/` | ||
fetch(apiUrl, { | ||
method: "GET", | ||
credentials: "include", | ||
mode: "cors", | ||
headers: { | ||
Accept: "application/json", | ||
}, | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
// create the login button | ||
const linkButton = document.createElement("a") | ||
const linkText = document.createTextNode(buttonText) | ||
linkButton.appendChild(linkText) | ||
linkButton.title = buttonText | ||
linkButton.href = loginUrl | ||
if (buttonClass !== "") { | ||
linkButton.classList.add(...buttonClass.split(" ")) | ||
} | ||
container.appendChild(linkButton) | ||
} | ||
return response.json() | ||
}) | ||
.then((data) => { | ||
if (data["username"] !== undefined) { | ||
// display the logged in user | ||
const userName = data["username"] | ||
const loggedInText = document.createElement("span") | ||
if (loggedInTextClass !== "") { | ||
loggedInText.classList.add(...loggedInTextClass.split(" ")) | ||
} | ||
loggedInText.textContent = `Logged in as: ${userName}` | ||
container.appendChild(loggedInText) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "mit-open-login-button", | ||
"packageManager": "[email protected]", | ||
"version": "0.0.1", | ||
"description": "A basic login button for your website to log in using MIT Open", | ||
"main": "index", | ||
"types": "index", | ||
"repository": "https://github.com/mitodl/mit-open-login-button", | ||
"author": "Carey Gumaer <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"lint": "eslint './**/*.{js,jsx,ts,tsx}'" | ||
}, | ||
"dependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.19.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-config-mitodl": "^1.0.0", | ||
"eslint-plugin-react": "^7.33.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"typescript": "^5.3.3", | ||
"typescript-eslint": "^0.0.1-alpha.0" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't want this.
(Do you want any typescript right now?)