Skip to content

Commit

Permalink
📝 write API [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Aug 16, 2018
1 parent 76d2196 commit c12c5f4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Socket.io Middleware firebase-admin
</a>
</p>

a minimal BDD interface / reporter for [ESM Modules](https://nodejs.org/api/esm.html#esm_enabling)
a socket.io middleware [firebaseAdmin.verifySessionCookie](https://firebase.google.com/docs/auth/admin/manage-cookies)

Installation
---
Expand All @@ -20,7 +20,66 @@ yarn add socket.io-middleware-firebase-admin

API
---
TODO

## createIoMiddlewareFirebaseAdmin({ credential }, (options = {})): middleware

[initialize "Firebase Admin SDK" using `credential`](https://firebase.google.com/docs/admin/setup)

```js
import { createServer } from "http";
import createIoServer from "socket.io";
import createIoClient from "socket.io-client";

import createIoMiddlewareFirebaseAdmin from "socket.io-middleware-firebase-admin";
import credential from "./.credential";

const server = createServer();
const io = createIoServer(server);
const ioMiddleware = createIoMiddlewareFirebaseAdmin({ credential });

io.use(ioMiddleware);

server.listen(() => {
const { port } = server.address();
const client = createIoClient(`http://localhost:${port}`, {
extraHeaders: {
Cookie: "session=" //+await firebaseAdmin.auth().createSessionCookie(idToken)
}
});
client.on("connect", error => {
const decodedClaims = ioMiddleware.getCache(client.id);
console.log(decodedClaims);
});
});
```

### `options`

* `options.deny`= true: boolean
Deny connections of users who couldn't authenticate.

* `options.cache`= true: boolean
Cache claim of authenticated user.

## ioMiddleware.getCache(clientId): decodedClaims

Returns the claim of the authenticated user.

```js
console.log(ioMiddleware.getCache(client.id));
// { iss:
// 'https://session.firebase.google.com/socketio-middleware-demo1',
// aud: 'socketio-middleware-demo1',
// auth_time: 1534417139,
// user_id: 'CUCPCuD50xgKeEfVggJ1fYQYNOj1',
// sub: 'CUCPCuD50xgKeEfVggJ1fYQYNOj1',
// iat: 1534417140,
// exp: 1534417440,
// email: '[email protected]',
// email_verified: false,
// firebase:
// { identities: { email: [Array] }, sign_in_provider: 'custom' }
```

License
---
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "socket.io-middleware-firebase-admin",
"version": "0.0.0",
"description": "",
"description": "a socket.io middleware firebaseAdmin.verifySessionCookie",
"scripts": {
"start": "abby format, test --watch \"*.mjs\"",
"test": "node --experimental-modules test.mjs",
"format": "prettier \"*.mjs\" --write",
"build": "babel index.mjs --out-file index.js",
"postversion": "git push --follow-tags && conventional-github-releaser -p atom"
},
"dependencies": {
"cookie": "^0.3.1",
"firebase-admin": "^6.0.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0-rc.1",
"@babel/core": "^7.0.0-rc.1",
Expand All @@ -24,10 +28,10 @@
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1"
},
"dependencies": {
"cookie": "^0.3.1",
"firebase-admin": "^6.0.0"
},
"keywords": [
"socket.io-middleware",
"firebase-admin"
],
"repository": {
"type": "git",
"url": "git+https://github.com/59naga/socket.io-middleware-firebase-admin.git"
Expand Down

0 comments on commit c12c5f4

Please sign in to comment.