Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
encyclopedia-gui
Commits
ec3fec46
Commit
ec3fec46
authored
Aug 21, 2020
by
Lauri Himanen
Browse files
Updated the authentication system to always provide the token in requests once logged in.
parent
669c75e4
Pipeline
#80857
skipped with stage
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
client/bundle.js
View file @
ec3fec46
This source diff could not be displayed because it is too large. You can
view the blob
instead.
client/conf.js
View file @
ec3fec46
...
...
@@ -6,7 +6,7 @@ window.nomadEnv = {
//apiRoot: "https://nomad-lab.eu/prod/rae/api/encyclopedia/",
//guiRoot: "https://nomad-lab.eu/prod/rae/encyclopedia/",
guiRoot
:
"
http://localhost:3000/gui/
"
,
apiRoot
:
"
http://localhost:
3
000/
"
,
apiRoot
:
"
http://localhost:
8
000/
fairdi/nomad/latest/api/encyclopedia/
"
,
userCookieDomain
:
"
.localhost
"
,
guestUserToken
:
'
eyJhbGciOiJIUzI1NiIsImlhdCI6MTUyMzg4MDE1OSwiZXhwIjoxNjgxNTYwMTU5fQ.ey
'
+
'
JpZCI6ImVuY2d1aSJ9.MsMWQa3IklH7cQTxRaIRSF9q8D_2LD5Fs2-irpWPTp4
'
,
...
...
client/src/common/FlaggingFormPopup.js
View file @
ec3fec46
...
...
@@ -205,15 +205,13 @@ sendButton.addEventListener('click', e => {
report
.
subcategory
=
subcategoryField
.
options
[
subcategoryField
.
selectedIndex
].
text
;
}
let
token
=
keycloak
.
token
;
util
.
serverReqPOST
(
util
.
getReportURL
(
materialId
),
JSON
.
stringify
(
report
),
e
=>
{
if
(
e
.
target
.
status
===
204
)
{
hide
();
}
else
{
validationMsg
.
innerHTML
=
"
Could not connect to the service. Please check your connection and try again later.
"
;
}
}
,
token
);
});
})
.
catch
(
error
=>
{
console
.
log
(
error
);
...
...
client/src/common/util.js
View file @
ec3fec46
...
...
@@ -41,8 +41,6 @@ let searchResults = false;
const
IMAGE_DIR
=
'
img/
'
;
const
AUTH_REQUEST_HEADER_GUEST_USER
=
'
Basic
'
+
btoa
(
window
.
nomadEnv
.
guestUserToken
+
'
:
'
);
const
MAT_VIEW
=
{
'
structure
'
:
'
structure
'
,
'
electronicstruct
'
:
'
electronicstruct
'
,
...
...
@@ -72,8 +70,6 @@ const API_BASE_URL = window.nomadEnv.apiRoot;
// Local variables
let
authRequestHeaderValue
=
AUTH_REQUEST_HEADER_GUEST_USER
;
//console.log('user: ANONYMOUS authRequestHeader: ',authRequestHeaderValue);
let
userData
=
null
;
...
...
@@ -130,41 +126,33 @@ function getShortCode(id) {
throw
"
The given identifier could not be shortened as it does not have the right initial length.
"
;
}
function
setAuthRequestHeader
(
userDataP
,
value
){
if
(
value
===
undefined
)
{
// default value
authRequestHeaderValue
=
AUTH_REQUEST_HEADER_GUEST_USER
;
userData
=
null
;
//console.log('user: ANONYMOUS authRequestHeader: ',authRequestHeaderValue);
}
else
{
authRequestHeaderValue
=
'
Basic
'
+
btoa
(
value
+
'
:
'
);
userData
=
userDataP
;
//console.log('user',user,'authRequestHeader: ',authRequestHeaderValue);
}
}
function
serverReq
(
url
,
callback
){
var
oReq
=
new
XMLHttpRequest
();
oReq
.
addEventListener
(
"
load
"
,
callback
);
oReq
.
open
(
"
GET
"
,
url
);
//console.log('authRequestHeaderValue: ',authRequestHeaderValue);
oReq
.
setRequestHeader
(
'
Authorization
'
,
authRequestHeaderValue
);
// Check for authentication
var
keycloak
=
window
.
keycloak
;
if
(
keycloak
.
authenticated
)
{
oReq
.
setRequestHeader
(
'
Authorization
'
,
'
Bearer
'
+
keycloak
.
token
);
}
oReq
.
send
();
return
oReq
;
}
function
serverReqPOST
(
url
,
data
,
callback
,
token
){
function
serverReqPOST
(
url
,
data
,
callback
){
var
oReq
=
new
XMLHttpRequest
();
oReq
.
addEventListener
(
'
load
'
,
callback
);
oReq
.
open
(
'
POST
'
,
url
);
oReq
.
setRequestHeader
(
'
Content-Type
'
,
'
application/json
'
);
if
(
token
!==
null
)
{
oReq
.
setRequestHeader
(
'
Authorization
'
,
'
Bearer
'
+
token
);
}
else
{
oReq
.
setRequestHeader
(
'
Authorization
'
,
authRequestHeaderValue
);
// Check for authentication
var
keycloak
=
window
.
keycloak
;
if
(
keycloak
.
authenticated
)
{
oReq
.
setRequestHeader
(
'
Authorization
'
,
'
Bearer
'
+
keycloak
.
token
);
}
oReq
.
send
(
data
);
return
oReq
;
}
...
...
@@ -443,7 +431,6 @@ module.exports = {
MAT_VIEW
:
MAT_VIEW
,
IMAGE_DIR
:
IMAGE_DIR
,
ELEMENTS
:
ELEMENTS
,
setAuthRequestHeader
,
getUserData
,
getServerLocation
,
authServerReq
,
...
...
client/src/main.js
View file @
ec3fec46
...
...
@@ -294,7 +294,7 @@ function parseCookie(userData) {
let
userInfoCookie
=
getCookie
(
'
user_info
'
);
if
(
userInfoCookie
!==
undefined
){
if
(
userInfoCookie
!==
undefined
)
{
let
userInfoData
=
JSON
.
parse
(
parseCookie
(
userInfoCookie
));
//console.log('userInfoData: ', userInfoData);
setAppAuthenticated
(
userInfoData
);
...
...
client/src/material-mod/NavTree.js
View file @
ec3fec46
...
...
@@ -304,7 +304,7 @@ class NavTree {
let
calcs
=
DataStore
.
getCalculations
();
let
calcIcon
=
document
.
createElement
(
"
img
"
);
calcIcon
.
className
=
"
folder-icon
"
;
calcIcon
.
src
=
+
util
.
IMAGE_DIR
+
"
folder.png
"
;
calcIcon
.
src
=
util
.
IMAGE_DIR
+
"
folder.png
"
;
// For the structure view we group calculations
let
groups
=
null
;
...
...
Write
Preview
Supports
Markdown
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