Skip to content

Commit e7b4d0f

Browse files
Extract auth api logic to oidc-auth-manager
1 parent 935be63 commit e7b4d0f

7 files changed

Lines changed: 6 additions & 179 deletions

File tree

‎default-email-templates/welcome.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
function render (data) {
1616
return {
17-
subject: `Welcome to Solid`,
17+
subject: 'Welcome to Solid',
1818

1919
/**
2020
* Text version of the Welcome email

‎lib/api/authn/webid-oidc.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const error = require('../../http-error')
1010
const bodyParser = require('body-parser').urlencoded({ extended: false })
1111

1212
const DiscoverProviderRequest = require('../../requests/discover-provider-request')
13-
const LogoutRequest = require('../../requests/logout-request')
1413

1514
const { LoginByPasswordRequest } = require('../../requests/login-request')
1615

@@ -43,8 +42,6 @@ function middleware (oidc) {
4342

4443
router.post(['/login', '/signin'], bodyParser, login)
4544

46-
router.get('/logout', logout)
47-
4845
router.get('/goodbye', (req, res) => {
4946
res.sendFile('goodbye.html', { root: './static/oidc/' })
5047
})
@@ -89,11 +86,6 @@ function login (req, res, next) {
8986
})
9087
}
9188

92-
function logout (req, res, next) {
93-
return LogoutRequest.handle(req, res)
94-
.catch(next)
95-
}
96-
9789
function authCodeFlowCallback (oidc, req) {
9890
debug.oidc('in authCodeFlowCallback()')
9991

@@ -161,7 +153,6 @@ module.exports = {
161153
middleware,
162154
discoverProvider,
163155
login,
164-
logout,
165156
extractWebId,
166157
authCodeFlowCallback,
167158
getIssuerId,

‎lib/create-app.js‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,6 @@ function initAuthentication (argv, app) {
191191
app.use('/', API.oidc.middleware(oidc))
192192

193193
oidc.initialize()
194-
.then(() => {
195-
oidc.saveProviderConfig()
196-
return oidc.clients.clientForIssuer(argv.serverUri)
197-
})
198-
.then(localClient => {
199-
console.log('Local RP client initialized')
200-
oidc.localRp = localClient
201-
})
202-
.catch(error => {
203-
console.error(error)
204-
})
205194

206195
// Enforce authentication with WebID-OIDC on all LDP routes
207196
app.use('/', oidc.rs.authenticate())

‎lib/models/oidc-manager.js‎

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const url = require('url')
4-
const debug = require('./../debug').oidc
4+
const debug = require('./../debug').authentication
55

66
const OidcManager = require('oidc-auth-manager')
7-
const LogoutRequest = require('../requests/logout-request')
87

98
/**
109
* Returns an instance of the OIDC Authentication Manager, initialized from
@@ -38,67 +37,12 @@ function fromServerConfig (argv) {
3837
authCallbackUri,
3938
postLogoutUri,
4039
saltRounds: argv.saltRounds,
41-
host: { authenticate, obtainConsent, logout }
40+
host: { debug }
4241
}
4342

4443
return OidcManager.from(options)
4544
}
4645

47-
// This gets called from OIDC Provider's /authorize endpoint
48-
function authenticate (authRequest) {
49-
let session = authRequest.req.session
50-
debug('AUTHENTICATE injected method')
51-
52-
if (session.identified && session.userId) {
53-
debug('User webId found in session: ', session.userId)
54-
55-
authRequest.subject = {
56-
_id: session.userId // put webId into the IDToken's subject claim
57-
}
58-
} else {
59-
// User not authenticated, send them to login
60-
debug('User not authenticated, sending to /login')
61-
62-
let loginUrl = url.parse('/login')
63-
loginUrl.query = authRequest.req.query
64-
loginUrl = url.format(loginUrl)
65-
authRequest.subject = null
66-
authRequest.res.redirect(loginUrl)
67-
}
68-
return authRequest
69-
}
70-
71-
function obtainConsent (authRequest) {
72-
if (authRequest.subject) {
73-
let { req, res } = authRequest
74-
75-
if (req.body.consent) {
76-
authRequest.consent = true
77-
authRequest.scope = authRequest.params.scope
78-
debug('OBTAINED CONSENT')
79-
} else {
80-
let params = req.query['client_id'] ? req.query : req.body
81-
82-
// let clientId = params['client_id']
83-
// let locals = req.app.locals
84-
// let clientStore = locals.oidc.clients
85-
86-
res.render('auth/consent', params)
87-
authRequest.headersSent = true
88-
}
89-
}
90-
91-
return authRequest
92-
}
93-
94-
function logout (logoutRequest) {
95-
return LogoutRequest.handle(logoutRequest.req, logoutRequest.res)
96-
.then(() => logoutRequest)
97-
}
98-
9946
module.exports = {
100-
fromServerConfig,
101-
authenticate,
102-
obtainConsent,
103-
logout
47+
fromServerConfig
10448
}

‎lib/requests/logout-request.js‎

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎package.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"node-forge": "^0.6.38",
5959
"nodemailer": "^3.1.4",
6060
"nomnom": "^1.8.1",
61-
"oidc-auth-manager": "^0.0.6",
61+
"oidc-auth-manager": "^0.1.0",
6262
"oidc-op-express": "^0.0.3",
6363
"rdflib": "^0.15.0",
6464
"recursive-readdir": "^2.1.0",
@@ -92,9 +92,8 @@
9292
"scripts": {
9393
"solid": "node ./bin/solid.js",
9494
"standard": "standard",
95-
"mocha": "nyc mocha ./test/*.js",
96-
"test": "npm run standard && npm run mocha",
9795
"mocha": "nyc mocha ./test/**/*.js",
96+
"test": "npm run standard && npm run mocha",
9897
"test-integration": "mocha ./test/integration/*.js",
9998
"test-unit": "mocha ./test/unit/*.js",
10099
"test-debug": "DEBUG='solid:*' ./node_modules/mocha/bin/mocha ./test/*.js",

‎test/unit/logout-request.js‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)