Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GSC React Auth
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GSC Libraries
GSC React Auth
Commits
c0212247
Commit
c0212247
authored
Feb 27, 2019
by
Ben Galloway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix logout issue; allow more granular login detection
parent
6e3eed4c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
dist/index.js
dist/index.js
+7
-1
package.json
package.json
+1
-1
src/index.js
src/index.js
+5
-2
No files found.
dist/index.js
View file @
c0212247
...
...
@@ -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
,
...
...
package.json
View file @
c0212247
{
"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>"
,
...
...
src/index.js
View file @
c0212247
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment