-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update social.coffee to generalize the Login to View system #44
base: master
Are you sure you want to change the base?
Changes from 4 commits
719f93e
6b0b771
a71ad0b
0a087d5
5b01de0
9652970
e9ab6be
94f729b
ec8e765
93a87b1
f10a887
0dfc857
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -385,24 +385,29 @@ module.exports = exports = (log, loga, argv) -> | |||
# see http://ward.asia.wiki.org/login-to-view.html | ||||
|
||||
if argv.restricted? | ||||
|
||||
allowedToView = (req) -> | ||||
allowed = [] | ||||
if argv.allowed_domains? | ||||
if Array.isArray(argv.allowed_domains) | ||||
allowed = argv.allowed_domains | ||||
else | ||||
# accommodate copy bug to be fixed soon | ||||
# https://github.com/fedwiki/wiki/blob/4c6eee69e78c1ba3f3fc8d61f4450f70afb78f10/farm.coffee#L98-L103 | ||||
for k, v of argv.allowed_domains | ||||
allowed.push v | ||||
# emails = [ { value: '[email protected]', type: 'account' } ] | ||||
emails = req.session?.passport?.user?.google?.emails | ||||
return false unless emails | ||||
for entry in emails | ||||
have = entry.value.split('@')[1] | ||||
for want in allowed | ||||
return true if want == have | ||||
try | ||||
allowed_domains = argv.allowed_domains | ||||
emails = req.session.passport.user.google.emails | ||||
for entry in emails | ||||
have = entry.value.split('@')[1] | ||||
for want in allowed_domains | ||||
return true if want == have | ||||
catch error | ||||
console.log "argv.allowed_domains exists, but there was an error. Make sure it's value is an array in your config." | ||||
if argv.allowed_usernames? | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the way this is written if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bortseb As per my earlier comment above, which is hopefully now visible to you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On my more recent commits, I changed the code so that both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to my lastest code here? because I changed things to try and account for this comment... I removed the returns in the catch block... So if the allowed_domains section doesn't return true, it should just move on to the next case of allowed_usernames correct? |
||||
try | ||||
allowed_usernames = argv.allowed_usernames | ||||
idProvider = _.head(_.keys(req.session.passport.user)) | ||||
switch idProvider | ||||
when 'github', 'twitter', 'oauth2' | ||||
Bortseb marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
username = req.session.passport.user[idProvider].username | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not all auth providers provide a username, and even when they do it is not immutable. The only thing that is immutable, and unique, is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean providers beyond the 4 that we currently account for in this plugin? (google, twitter, github, oauth2) Other than Google, which is dealt with separately in the Is it a big issue that the usernames aren't immutable? (if someone changed their username, the config would need to be changed to match) I kind of like that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The single prior use case for login to view which created Authentication is done using the unique ID that the identity provider provides - and is stored in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what other providers also provide an email in the token, but the use of Google was kind of hard-coded into the existing code here on line 400. wiki-security-passportjs/server/social.coffee Line 400 in 99e2594
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just switch to using id, instead of username then. |
||||
return true if (allowed_usernames.length == 1 and allowed_usernames[0] == "*") | ||||
for want in allowed_usernames | ||||
return true if want == username | ||||
catch error | ||||
console.log "argv.allowed_usernames exists, but there was an error. Make sure it's value is an array in your config." | ||||
false | ||||
|
||||
app.all '*', (req, res, next) -> | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was like it for a reason. @WardCunningham are we really sure it is not still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?