-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/anthonyhardman/project_aspen
- Loading branch information
Showing
7 changed files
with
222 additions
and
3 deletions.
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
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 @@ | ||
BROWSER=none | ||
REACT_APP_AUTH_URL=https://engineering.snow.edu/aspen/auth | ||
REACT_APP_BASE_URL=https://localhost:44478/aspen/new |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 @@ | ||
import { authService } from "../services/authService"; | ||
|
||
export const LoginButton = () => { | ||
const loginHandler = () => { | ||
authService.signinRedirect(); | ||
}; | ||
const logoutHandler = () => { | ||
authService.logout(); | ||
}; | ||
|
||
|
||
return ( | ||
<> | ||
{localStorage.getItem("LoggedInUser") === "" ? ( | ||
<button className="btn btn-secondary shadow text-white" onClick={loginHandler}>Login</button> | ||
) : ( | ||
<button className="btn btn-secondary shadow text-white" onClick={logoutHandler}>Logout</button> | ||
)} | ||
</> | ||
); | ||
}; |
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
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,100 @@ | ||
import { UserManager, WebStorageStateStore } from "oidc-client"; | ||
|
||
const authUrl = process.env.REACT_APP_AUTH_URL | ||
var redirectUrl = "/landing/" | ||
var userManager = new UserManager({ | ||
userStore: new WebStorageStateStore({ store: window.localStorage }), | ||
authority: | ||
`${authUrl || "https://engineering.snow.edu/aspen/auth"}/realms/aspen/.well-known/openid-configuration`, | ||
client_id: "aspen-web", | ||
redirect_uri: window.location.origin + redirectUrl, | ||
post_logout_redirect_uri: window.location.origin + "/aspen/new/", | ||
silent_redirect_uri: window.location.origin + "/aspen/new/", | ||
response_type: "code", | ||
scope: "openid profile email", | ||
loadUserInfo: true, | ||
automaticSilentRenew: true, | ||
}); | ||
|
||
userManager.startSilentRenew(); | ||
|
||
export const authService = { | ||
|
||
getUser: async () => { | ||
const user = await userManager.getUser(); | ||
return user; | ||
}, | ||
|
||
isLoggedIn: async () => { | ||
const user = await userManager.getUser(); | ||
const loggedIn = user !== null && !user.expired; | ||
return loggedIn; | ||
}, | ||
|
||
signinRedirect: async () => { | ||
|
||
const params = new URLSearchParams(window.location.search) | ||
var redirectUri = window.location.pathname.replace("/aspen/new", "") | ||
|
||
localStorage.setItem("redirectUri", redirectUri) | ||
if (window.location.pathname === '/aspen/new/') { | ||
localStorage.setItem("redirectUri", '/'); | ||
} | ||
else if(redirectUri === "/TeamDetails"){ | ||
localStorage.setItem("redirectUri", `${redirectUri}?teamId=${params.get("teamId")}&ownerID=${params.get("ownerID")} `); | ||
} | ||
await userManager.signinRedirect(); | ||
}, | ||
|
||
signinRedirectCallback: async () => { | ||
const desiredDestination = localStorage.getItem("redirectUri"); | ||
const tempDestination = desiredDestination?.replace('/login', '/'); | ||
const user = await userManager.signinRedirectCallback(); | ||
return { desiredDestination: tempDestination, user }; | ||
}, | ||
|
||
signinSilent: async () => { | ||
await userManager | ||
.signinSilent() | ||
.then((user) => { | ||
}) | ||
.catch((err) => { | ||
}); | ||
}, | ||
|
||
signinSilentCallback: async () => { | ||
return await userManager.signinSilentCallback(); | ||
}, | ||
|
||
createSigninRequest: async () => { | ||
return await userManager.createSigninRequest(); | ||
}, | ||
|
||
logout: async () => { | ||
await userManager.clearStaleState(); | ||
await userManager.signoutRedirect(); | ||
localStorage.setItem("LoggedInUser", "") | ||
localStorage.setItem("LoggedInEmail", "") | ||
localStorage.setItem("access_token", "") | ||
|
||
// await userManager.signoutRedirect({ | ||
// id_token_hint: localStorage.getItem("id_token"), | ||
// }); | ||
}, | ||
|
||
signoutRedirectCallback: async () => { | ||
await userManager.signoutRedirectCallback().then(() => { | ||
localStorage.clear(); | ||
window.location.replace('/'); | ||
}); | ||
await userManager.clearStaleState(); | ||
}, | ||
|
||
} | ||
|
||
userManager.events.addSilentRenewError((e) => { | ||
}); | ||
|
||
userManager.events.addAccessTokenExpired(() => { | ||
authService.signinSilent(); | ||
}); |