Skip to content

Add documentation about hooking authorization for SocketIO #63

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ Sessions work automatically, just set them up like normal using express.
app.use(express.session({secret: 'express.io makes me happy'}));
```

**Please note** that the SocketIO session support is given by using the SocketIO
authorization handler. Thus, if there is a need to implement your own authorization
it should use the existing authorization handler and wrap it.

Here is a small example of a custom handler that uses passport to validate socket
requests except when on the login page.

```js
//use passport to authenticate our socket.io connections
var ioAuthorization = app.io.get("authorization")
app.io.set("authorization",function(data,accept){
ioAuthorization(data,function(err,res){
if(null !== err) accept(err,res)
if(!data.session[passport._key][passport._userProperty] && !data.headers.referer.match(/login/)){
accept(null,false)
} else accept(null,true)
})
})
```

## Double Up - Forward Normal Http Routes to Realtime Routes

It's easy to forward regular http routes to your realtime routes.
Expand Down