-
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 6 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,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,21 @@ | ||
name: CI | ||
on: [push] | ||
|
||
jobs: | ||
javascript-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.8.1 | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Code formatting | ||
run: yarn fmt:check |
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,58 @@ | ||
/** | ||
* 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 reconstructedBaseUrl = `${parsedBaseUrl.protocol}//${parsedBaseUrl.hostname}${parsedBaseUrl.port !== "" ? `:${parsedBaseUrl.port}` : ""}` | ||
const apiUrl = `${reconstructedBaseUrl}/api/v0/users/me?format=json` | ||
const loginUrl = `${reconstructedBaseUrl}/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,25 @@ | ||
{ | ||
"name": "mit-open-login-button", | ||
"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}'", | ||
"fmt": "yarn fmt:check --write", | ||
"fmt:check": "LOG_LEVEL= prettier-eslint --list-different './**/*.{js,jsx,ts,tsx,scss}'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strong Suggestion: Don't use |
||
}, | ||
"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", | ||
"prettier-eslint": "^16.3.0", | ||
"prettier-eslint-cli": "^8.0.1" | ||
} | ||
} |
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.
Is this the same as
parsedBaseUrl.origin
?