-
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
Open
Bortseb
wants to merge
12
commits into
fedwiki:master
Choose a base branch
from
Bortseb:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
719f93e
Update social.coffee
Bortseb 6b0b771
Update social.coffee
Bortseb a71ad0b
Update social.coffee
Bortseb 0a087d5
Update social.coffee
Bortseb 5b01de0
Update configuration.md
Bortseb 9652970
Create config-login-to-view.md
Bortseb e9ab6be
Update config-login-to-view.md
Bortseb 94f729b
Update config-login-to-view.md
Bortseb ec8e765
switching to authorizing based on id
Bortseb 93a87b1
Update config-login-to-view.md
Bortseb f10a887
Update config-login-to-view.md
Bortseb 0dfc857
Update config-login-to-view.md
Bortseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Federated Wiki - Security Plug-in: Passport | ||
## (Configuring "Login to View") | ||
|
||
Before attempting to configure Login to View, make sure you have already taken the steps to configure your identity provider as explained [earlier in the documentation](./configuration.md) | ||
|
||
Where you put your configuration for the Login to View system depends on which sites on your farm you want to be restricted. If you want the whole farm to be restricted then you would add the key-value pairs into the top level of your wiki's `config.json`. If you only want to restrict specific sites on your farm, then you need to restrict them individually within a wikiDomains section of your config. | ||
|
||
The properties we need to add for Login to View are: `restricted`, `details`, and either `allowed_domains` (Google) or `allowed_ids` (GitHub, Twitter, OAuth2) depending on your identity provider. When using Google auth, `allowed_domains` allows you to specify which domains your user's emails are allowed to be from. Only users with email domains included in this array will be allowed to view the restricted sites. When using GitHub, Twitter, or OAuth2, `allowed_ids` allows you to specify an array of user IDs that are allowed to view the restricted sites. If you set `allowed_ids` equal to `[*]` then any user in your identity provider's system will be allowed to view the restricted sites. | ||
|
||
**Examples:** | ||
|
||
If your identity provider is **Google**: | ||
```json | ||
{ | ||
"admin": {"google":"105396921212328672315"}, | ||
"farm": true, | ||
"cookieSecret": "0ebf86563b4sdfsdfcc8788e666702", | ||
"secure_cookie": true, | ||
"security_type": "passportjs", | ||
"security_useHttps": true, | ||
"allowed": "*", | ||
"wikiDomains": { | ||
"private.example.com": { | ||
"admin": {"google":"105396921212328672315"}, | ||
"google_clientID": "10030fghfgh7443-gcemshdl37j67mgpm99eu5dh43li5vrs.apps.googleusercontent.com", | ||
"google_clientSecret": "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", | ||
"restricted": true, | ||
"details": "http://path.ward.asia.wiki.org/login-to-view.html", | ||
"allowed_domains": [ | ||
"example1.com", | ||
"example2.com" | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
If your identity provider is **GitHub**, **Twitter**, or generic **OAuth2**: | ||
```json | ||
{ | ||
"admin": {"oauth2": "admin"}, | ||
"farm": true, | ||
"cookieSecret": "FDpmzFT2FQZsdfsdfFr4WwZFGuwuVSQ", | ||
"secure_cookie": true, | ||
"security_type": "passportjs", | ||
"security_useHttps": true, | ||
"allowed": "*", | ||
"wikiDomains": { | ||
"wiki.example.com": { | ||
"oauth2_DisplayNameField": "token.preferred_username", | ||
"oauth2_IdField": "token.preferred_username", | ||
"oauth2_clientID": "wiki", | ||
"oauth2_clientSecret": "3Df5D3jNfsdfsdfsdfNvc08iJOL3uSCg", | ||
"oauth2_AuthorizationURL": "https://auth.example.com/realms/wiki-cafe-test-server/protocol/openid-connect/auth", | ||
"oauth2_TokenURL": "https://auth.example.com/realms/wiki-cafe-test-server/protocol/openid-connect/token", | ||
"oauth2_UsernameField": "token.preferred_username", | ||
"restricted": true, | ||
"details": "http://path.ward.asia.wiki.org/login-to-view.html", | ||
"allowed_ids": ["*"] | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,24 +385,31 @@ 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 | ||
if emails? | ||
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_ids? | ||
try | ||
allowed_ids = argv.allowed_ids | ||
idProvider = _.head(_.keys(req.session.passport.user)) | ||
switch idProvider | ||
when 'github', 'twitter', 'oauth2' | ||
Bortseb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id = req.session.passport.user[idProvider].id | ||
return true if (allowed_ids.length == 1 and allowed_ids[0] == "*") | ||
for want in allowed_ids | ||
return true if want == id | ||
catch error | ||
if idProvider? | ||
console.log "argv.allowed_ids exists, but there was an error. Make sure it's value is an array in your config." | ||
false | ||
|
||
app.all '*', (req, res, next) -> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
?