-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #837 from palladiumkenya/prod
Prod update
- Loading branch information
Showing
3 changed files
with
79 additions
and
4 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
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,73 @@ | ||
import { UserManager } from 'oidc-client'; | ||
import { storeUser, storeUserError } from '../actions/Shared/AuthActions'; | ||
let config = {}; | ||
|
||
if(process.env) { | ||
config = { | ||
authority: process.env.REACT_APP_AUTHORITY, | ||
client_id: "nascop.spa", | ||
redirect_uri: process.env.REACT_APP_REDIRECT_URI, | ||
response_type: 'id_token token', | ||
scope: process.env.REACT_APP_SCOPE, | ||
post_logout_redirect_uri: | ||
process.env.REACT_APP_POST_LOGOUT_REDIRECT_URI, | ||
filterProtocolClaims: process.env.REACT_APP_FILTER_PROTOCOL_CLAIMS, | ||
}; | ||
} else { | ||
// client_id: process.env.REACT_APP_CLIENT, | ||
config = { | ||
authority: "https://auth.kenyahmis.org/dwhidentity", | ||
client_id: "dwh.spa", | ||
redirect_uri: "https://data.kenyahmis.org:9000/#/signin-oidc#", | ||
response_type: "id_token token", | ||
scope: "openid profile apiApp", | ||
post_logout_redirect_uri: "https://data.kenyahmis.org:9000", | ||
} | ||
} | ||
|
||
const userManager = new UserManager(config); | ||
|
||
export async function loadUserFromStorage(store) { | ||
try { | ||
let user = await userManager.getUser(); | ||
if (!user) { return store.dispatch(storeUserError()); } | ||
store.dispatch(storeUser(user)); | ||
} catch (e) { | ||
console.error(`User not found: ${e}`) | ||
store.dispatch(storeUserError()) | ||
} | ||
} | ||
|
||
export function signinRedirect() { | ||
return userManager.signinRedirect(); | ||
} | ||
|
||
export function signinRedirectCallback() { | ||
if (window.location.hash) { | ||
try { | ||
return userManager.signinRedirectCallback(); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
} else { | ||
return userManager.signinRedirectCallback(); | ||
} | ||
} | ||
|
||
export async function signoutRedirect() { | ||
let user = await userManager.getUser(); | ||
await userManager.clearStaleState(); | ||
await userManager.removeUser(); | ||
return userManager.signoutRedirect({ 'id_token_hint': user.id_token }); | ||
} | ||
|
||
export function signoutRedirectCallback() { | ||
userManager.clearStaleState(); | ||
userManager.removeUser(); | ||
return userManager.signoutRedirectCallback(); | ||
} | ||
|
||
export default userManager; | ||
|
||
|