Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Auth stream
- A stream that authorizes your client before it allows data through to your secret stream.
- On the client pipe your stream into the auth stream and out. Then login in to the auth stream.
- On the server, handle your login logic in the auth stream and pass it a secret stream to give access to once authorized.
- ``` js
- var Auth = require("auth")
- , net = require("net")
- , through = require("through")
- net.createServer(function (stream) {
- var secret = through(function (data) {
- console.log(data === "anything")
- this.emit("data", "secret")
- })
- , auth = Auth(secret, function (user, pass) {
- if (user === "steve" && pass === "jones") {
- return true
- }
- })
- stream.pipe(auth).pipe(stream)
- }).listen(8080, function () {
- var stream = net.connect(8080)
- , auth = Auth()
- stream.pipe(auth).pipe(stream)
- stream.on("data", function (secret) {
- console.log(secret === "secret")
- })
- // login(user, pass)
- auth.login("steve", "jones")
- stream.write("anything")
- })
- ```
Add Comment
Please, Sign In to add comment