Skip to content

Commit

Permalink
feat: Simple login flow
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Dec 4, 2019
1 parent d6f48d0 commit 8d6042a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 203 deletions.
1 change: 0 additions & 1 deletion examples/expressjs-ethr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"express-socket.io-session": "^1.3.5",
"http": "^0.0.0",
"lodash.merge": "^4.6.2",
"ngrok": "^3.2.5",
"socket.io": "^2.3.0",
"ts-node": "^8.5.0",
"typescript": "^3.7.2"
Expand Down
34 changes: 22 additions & 12 deletions examples/expressjs-ethr/src/web-server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as ngrok from 'ngrok'
import express from 'express'
import * as Daf from 'daf-core'
import * as SD from 'daf-selective-disclosure'
import * as W3C from 'daf-w3c'
import session from 'express-session'
import session, { MemoryStore } from 'express-session'
import socketio from 'socket.io'
import http from 'http'
import exphbs from 'express-handlebars'
Expand All @@ -18,11 +17,13 @@ const debug = Debug('main')

const app = express()
app.use(bodyParser.text())
const sessionStore = new MemoryStore()
const sess = session({
secret: 'keyboard cat',
cookie: { maxAge: 60000 },
cookie: { maxAge: 10 * 60000 },
saveUninitialized: true,
resave: true,
store: sessionStore,
})
app.use(sess)

Expand Down Expand Up @@ -115,20 +116,29 @@ async function main() {
await dataStore.saveMessage(message)
if (message.type === W3C.MessageTypes.vp && message.tag) {
// TODO check for required vcs
console.log('AAAAAAA')
await io.in(message.tag).emit('loggedin', { did: message.issuer })

const sessionId = message.tag
await io.in(sessionId).emit('loggedin', { did: message.issuer })
sessionStore.get(sessionId, (error, session) => {
if (error) {
console.log(error)
return
}
if (session) {
console.log('Got session', session)
console.log('View count', session.viewcount)
session.did = message.issuer
sessionStore.set(sessionId, session)
} else {
console.log('No session: ' + message.tag)
}
})
}
})

const port = 8099
server.listen(port, async () => {
debug(`Listening on port ${port}!`)
const url = await ngrok.connect({
addr: port,
subdomain: 'someservice',
region: 'eu',
})
debug(`URL: ${url}`)
console.log(`Server running at http://localhost:${port}/`)

await core.startServices()
await core.syncServices(await dataStore.latestMessageTimestamps())
Expand Down
5 changes: 4 additions & 1 deletion examples/expressjs-ethr/views/login.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<h1>You need to login</h1>

<img src="https://chart.googleapis.com/chart?chs=400x400&cht=qr&chl={{jwt}}&choe=UTF-8" width="400" height="400"/>

<div>Waiting for response...</div>
<div style="margin-top: 40px;word-wrap: break-word;">
{{jwt}}

</div>
</div>

<div id="success"></div>
Loading

0 comments on commit 8d6042a

Please sign in to comment.