Commit c0212247 authored by Ben Galloway's avatar Ben Galloway

Fix logout issue; allow more granular login detection

parent 6e3eed4c
......@@ -27,6 +27,10 @@ var hasValidLogin = function hasValidLogin(authValues) {
return token && !tokenIsExpired(token);
};
var isLoggedIn = function isLoggedIn() {
return Boolean(_msalB2cReact.default.getUserName());
};
var runGSCAuth = _msalB2cReact.default.run;
var requireGSCAuth = _msalB2cReact.default.required;
......@@ -45,6 +49,7 @@ var initGSCAuth = function initGSCAuth(applicationId, redirectUri, scopes, cache
_msalB2cReact.default.initialize({
instance: "https://login.microsoftonline.com/",
tenant: "f62a415a-76c0-4075-9eb3-f31250de2db2",
// or glasgowsciencecentre.onmicrosoft.com
signInPolicy: "",
resetPolicy: "",
applicationId: applicationId,
......@@ -76,7 +81,7 @@ var setupGSCAuth = function setupGSCAuth(aadAppId, authRedirectUri) {
var initialAuthValues = getAuthValues();
var clearGSCAuth = function clearGSCAuth() {
return window[cacheLocation].clear();
return _msalB2cReact.default.signOut();
};
return {
......@@ -84,6 +89,7 @@ var setupGSCAuth = function setupGSCAuth(aadAppId, authRedirectUri) {
GSCAuthConsumer: GSCAuthConsumer,
initialAuthValues: initialAuthValues,
getAuthValues: getAuthValues,
isLoggedIn: isLoggedIn,
hasValidLogin: hasValidLogin,
runGSCAuth: runGSCAuth,
requireGSCAuth: requireGSCAuth,
......
{
"name": "@gsc/react-auth",
"version": "1.0.0",
"version": "1.1.0",
"description": "React components to obtain a JWT from MS AAD and make it available on Context for use in API calls",
"main": "dist/index.js",
"author": "Ben Galloway <ben.galloway@gsc.org.uk>",
......
......@@ -17,6 +17,8 @@ const hasValidLogin = authValues => {
return token && !tokenIsExpired(token);
};
const isLoggedIn = () => Boolean(authentication.getUserName());
const runGSCAuth = authentication.run;
const requireGSCAuth = authentication.required;
......@@ -33,7 +35,7 @@ const initGSCAuth = (applicationId, redirectUri, scopes, cacheLocation) => {
throw new Error("GSCAuth must be provided with a redirect URI, as configured in the Azure AD portal");
authentication.initialize({
instance: "https://login.microsoftonline.com/",
tenant: "f62a415a-76c0-4075-9eb3-f31250de2db2",
tenant: "f62a415a-76c0-4075-9eb3-f31250de2db2", // or glasgowsciencecentre.onmicrosoft.com
signInPolicy: "",
resetPolicy: "",
applicationId,
......@@ -54,13 +56,14 @@ const initGSCAuth = (applicationId, redirectUri, scopes, cacheLocation) => {
const setupGSCAuth = (aadAppId, authRedirectUri, msGraphScopes = ["User.Read"], cacheLocation = "sessionStorage") => {
const { GSCAuthProvider, GSCAuthConsumer } = initGSCAuth(aadAppId, authRedirectUri, msGraphScopes, cacheLocation);
const initialAuthValues = getAuthValues();
const clearGSCAuth = () => window[cacheLocation].clear();
const clearGSCAuth = () => authentication.signOut();
return {
GSCAuthProvider,
GSCAuthConsumer,
initialAuthValues,
getAuthValues,
isLoggedIn,
hasValidLogin,
runGSCAuth,
requireGSCAuth,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment