Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
PUBLIC
/
surfer-okd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dcb20866
authored
Nov 17, 2016
by
Johannes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement local file auth
1 parent
5a242369
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
src/auth.js
src/auth.js
View file @
dcb2086
'use strict'
;
'use strict'
;
var
passport
=
require
(
'passport'
),
var
passport
=
require
(
'passport'
),
path
=
require
(
'path'
),
safe
=
require
(
'safetydance'
),
bcrypt
=
require
(
'bcryptjs'
),
LdapStrategy
=
require
(
'passport-ldapjs'
).
Strategy
;
LdapStrategy
=
require
(
'passport-ldapjs'
).
Strategy
;
var
LOCAL_AUTH_FILE
=
path
.
resolve
(
process
.
env
.
LOCAL_AUTH_FILE
||
'./.users.json'
);
passport
.
serializeUser
(
function
(
user
,
done
)
{
passport
.
serializeUser
(
function
(
user
,
done
)
{
console
.
log
(
'serializeUser'
,
user
);
console
.
log
(
'serializeUser'
,
user
);
done
(
null
,
user
.
uid
);
done
(
null
,
user
.
uid
);
...
@@ -21,13 +26,17 @@ if (LDAP_URL && LDAP_USERS_BASE_DN) {
...
@@ -21,13 +26,17 @@ if (LDAP_URL && LDAP_USERS_BASE_DN) {
exports
.
ldap
=
passport
.
authenticate
(
'ldap'
);
exports
.
ldap
=
passport
.
authenticate
(
'ldap'
);
}
else
{
}
else
{
exports
.
ldap
=
function
(
req
,
res
,
next
)
{
console
.
log
(
'Use local user file:'
,
LOCAL_AUTH_FILE
);
console
.
log
(
'Disable ldap auth, use developer credentials!'
);
if
(
req
.
query
.
username
!==
'test'
)
return
res
.
send
(
401
);
exports
.
ldap
=
function
(
req
,
res
,
next
)
{
if
(
req
.
query
.
password
!==
'test'
)
return
res
.
send
(
401
);
var
users
=
safe
.
JSON
.
parse
(
safe
.
fs
.
readFileSync
(
LOCAL_AUTH_FILE
));
if
(
!
users
)
return
res
.
send
(
401
);
next
();
if
(
!
users
[
req
.
query
.
username
])
return
res
.
send
(
401
);
bcrypt
.
compare
(
req
.
query
.
password
,
users
[
req
.
query
.
username
].
passwordHash
,
function
(
error
,
valid
)
{
if
(
error
||
!
valid
)
return
res
.
send
(
401
);
next
();
});
};
};
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment