Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Wolfgang Knopki
Spacedeck-open-SAML
Commits
9d956240
Commit
9d956240
authored
Sep 17, 2020
by
Wolfgang Knopki
Browse files
[fix] saml auth finished
parent
f0b219f5
Pipeline
#975
failed with stages
in 2 minutes and 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
routes/root.js
View file @
9d956240
...
...
@@ -64,35 +64,98 @@ const uuidv4 = require('uuid/v4');
router
.
post
(
'
/saml/SSO
'
,
passport
.
authenticate
(
'
saml
'
,
{
failureRedirect
:
'
/login
'
,
failureFlash
:
true
}),
function
(
req
,
res
){
const
xmlResponse
=
req
.
body
.
SAMLResponse
;
const
parser
=
new
Saml2js
(
xmlResponse
);
const
userid
=
parser
.
get
(
'
email
'
);
const
response
=
parser
.
toObject
();
const
email
=
response
[
"
mail
"
];
console
.
log
(
parser
.
toJSON
());
console
.
log
(
"
Nickname
"
+
response
[
"
givenName
"
])
const
nickname
=
response
[
"
givenName
"
];
//check, if user exists, if not create.
//else get userid and create session -> set cookie
crypto
.
randomBytes
(
48
,
function
(
ex
,
buf
)
{
var
token
=
buf
.
toString
(
'
hex
'
);
var
session
=
{
user_id
:
userid
,
token
:
token
,
ip
:
req
.
ip
,
device
:
"
web
"
,
created_at
:
new
Date
(),
url
:
"
/
"
};
db
.
Session
.
create
(
session
)
db
.
User
.
findAll
({
where
:
{
email
:
email
}})
.
then
(
users
=>
{
if
(
users
.
length
==
0
)
{
crypto
.
randomBytes
(
16
,
function
(
ex
,
buf
)
{
var
token
=
buf
.
toString
(
'
hex
'
);
var
u
=
{
_id
:
uuidv4
(),
email
:
email
,
account_type
:
"
email
"
,
nickname
:
nickname
,
password_hash
:
"
00000
"
,
prefs_language
:
req
.
i18n
.
locale
,
confirmation_token
:
token
};
db
.
User
.
create
(
u
)
.
error
(
err
=>
{
res
.
sendStatus
(
400
);
})
.
then
(
u
=>
{
var
homeFolder
=
{
_id
:
uuidv4
(),
name
:
req
.
i18n
.
__
(
"
home
"
),
space_type
:
"
folder
"
,
creator_id
:
u
.
_id
};
db
.
Space
.
create
(
homeFolder
)
.
error
(
err
=>
{
res
.
sendStatus
(
400
);
})
.
then
(
homeFolder
=>
{
u
.
home_folder_id
=
homeFolder
.
_id
;
u
.
save
()
.
then
(()
=>
{
// home folder created,
// auto accept pending invites
db
.
Membership
.
update
({
"
state
"
:
"
active
"
},
{
where
:
{
"
email_invited
"
:
u
.
email
,
"
state
"
:
"
pending
"
}
});
res
.
status
(
201
).
json
({});
})
.
error
(
err
=>
{
res
.
status
(
400
).
json
(
err
);
});
})
});
});
}
}).
then
(
user
=>
{
db
.
User
.
findOne
({
where
:
{
email
:
email
}})
.
error
(
err
=>
{
console
.
error
(
"
Error creating Session:
"
,
err
);
res
.
redirect
(
500
,
"
/
"
);
res
.
sendStatus
(
404
);
})
.
then
(()
=>
{
var
domain
=
(
process
.
env
.
NODE_ENV
==
"
production
"
)
?
new
URL
(
config
.
get
(
'
endpoint
'
)).
hostname
:
req
.
headers
.
hostname
;
res
.
cookie
(
'
sdsession
'
,
token
,
{
domain
:
domain
,
httpOnly
:
true
});
res
.
redirect
(
302
,
"
/
"
)
.
then
(
user
=>
{
crypto
.
randomBytes
(
48
,
function
(
ex
,
buf
)
{
var
token
=
buf
.
toString
(
'
hex
'
);
var
session
=
{
user_id
:
user
.
_id
,
token
:
token
,
ip
:
req
.
ip
,
device
:
"
web
"
,
created_at
:
new
Date
(),
url
:
"
/
"
};
db
.
Session
.
create
(
session
)
.
error
(
err
=>
{
console
.
error
(
"
Error creating Session:
"
,
err
);
res
.
redirect
(
500
,
"
/
"
);
})
.
then
(()
=>
{
var
domain
=
(
process
.
env
.
NODE_ENV
==
"
production
"
)
?
new
URL
(
config
.
get
(
'
endpoint
'
)).
hostname
:
req
.
headers
.
hostname
;
console
.
log
(
"
session set successfully
"
);
res
.
cookie
(
'
sdsession
'
,
token
,
{
domain
:
domain
,
httpOnly
:
true
});
res
.
redirect
(
302
,
"
/
"
)
});
});
});
});
});
});
router
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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