max-mapper / max-mapper/auth-socket

API for other services

Open
#1 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
7
Forks
1
PR merge metrics
No merged PRs in 30d

Description

We talked about changing the API up to be more forgiving for other authentication services.

I made a gist ( https://gist.github.com/Raynos/7651349 )

The idea is simple, auth-socket at it's simplest should be

`function auth(req, socket, head, callback) {}`

and it should do `callback(err)` or `callback(err, user)` or `callback(err, null)` where `null` means anonymous

As a user you want to do something like

``` js
var AuthSocket = require("auth-socket")

var auth = AuthSocket({
allowAnonymous: true,
authHandler: function (req, socket, head, cb) {
// read cookie
// read session
// return the user from session store
},
// OR
authHandler: doorKnob.createAuthHandler()
// OR
authHandler: githubOAuth.createAuthHandler()
})
```

With that kind of API you don't have to build a massive switch in auth-socket to support doorknob & github oauth & redsess & level-session & bla bla.

In the gist i also showed this example

``` js
var http = require("http")
var WebsocketServer = require("ws").Server
var Router = require("routes-router")
var AuthSocket = require("auth-socket")

var app = Router()
var auth = AuthSocket({
authHandler: function (req, socket, head, cb) {}
})
var server = http.createServer(app)

var wss = new WebsocketServer({ noSserver: true })
wss.on("connection", function (stream, user) {
// if `user` is null then it's anonymous
})

server.on("upgrade", auth.handleUpgrade(ws))

server.listen(3000)
```

Which is the higher level way of using it with `auth.handleUpgrade`. Note this api means `auth-socket` does not depend on `http` or `ws` and nor does it create servers for you.

We can have an even less lines of code api similar to the current api if wanted

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing auth-socket API and the issue's proposed auth(req, socket, head, callback) and auth.handleUpgrade entry points. Review the linked gist for the intended higher-level usage; done means authentication handlers can return a user or anonymous null without auth-socket depending on http, ws, or specific authentication services.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, authentication, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.