forked from nodeSolidServer/node-solid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accounts API v1 (nodeSolidServer#339)
* implemented signout * designing the scenario for accounts with OIDC * adding waterfall * adding scenario workflow * put all the APIs under /api * Update scenarios.md * adding scenario folders * enabling webid * starting writing first test * rename to test/api-accounts * skipping tests for now * first implementation of signin endpoint * implementing signin * adding lib/api * adding APIs and renaming folders in gitignore * 406 to 400 * turn all errors into 400 * update tests to 400 * missing a 400 * from oidc to oidc issuer * missed oidc.issuer * implementing OIDC for new account creation (nodeSolidServer#349) * implementing OIDC for new account creation * adding create user call in new * oidc in new * client is under .client * adding password * Remove unused requires * skipping oidc if no provider is found
- Loading branch information
Showing
18 changed files
with
287 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
config.json.bck | ||
config.json | ||
test | ||
accounts | ||
settings | ||
profile | ||
.acl | ||
inbox | ||
./accounts | ||
./settings | ||
./profile | ||
./.acl | ||
./inbox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
signin: require('./signin'), | ||
signout: require('./signout') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = signin | ||
|
||
const validUrl = require('valid-url') | ||
const request = require('request') | ||
const li = require('li') | ||
|
||
function signin () { | ||
return (req, res, next) => { | ||
if (!validUrl.isUri(req.body.webid)) { | ||
return res.status(400).send('This is not a valid URI') | ||
} | ||
|
||
request({ method: 'OPTIONS', uri: req.body.webid }, function (err, req) { | ||
if (err) { | ||
res.status(400).send('Did not find a valid endpoint') | ||
return | ||
} | ||
if (!req.headers.link) { | ||
res.status(400).send('The URI requested is not a valid endpoint') | ||
return | ||
} | ||
|
||
const linkHeaders = li.parse(req.headers.link) | ||
console.log(linkHeaders) | ||
if (!linkHeaders['oidc.issuer']) { | ||
res.status(400).send('The URI requested is not a valid endpoint') | ||
return | ||
} | ||
|
||
res.redirect(linkHeaders['oidc.issuer']) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = signout | ||
|
||
function signout () { | ||
return (req, res, next) => { | ||
req.session.userId = '' | ||
req.session.identified = false | ||
res.status(200).send() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
accounts: require('./accounts') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
const Solid = require('../') | ||
const parallel = require('run-parallel') | ||
const waterfall = require('run-waterfall') | ||
const path = require('path') | ||
const supertest = require('supertest') | ||
const expect = require('chai').expect | ||
const nock = require('nock') | ||
// In this test we always assume that we are Alice | ||
|
||
describe('API', () => { | ||
let aliceServer | ||
let bobServer | ||
let alice | ||
let bob | ||
|
||
const alicePod = Solid.createServer({ | ||
root: path.join(__dirname, '/resources/accounts-scenario/alice'), | ||
sslKey: path.join(__dirname, '/keys/key.pem'), | ||
sslCert: path.join(__dirname, '/keys/cert.pem'), | ||
auth: 'oidc', | ||
dataBrowser: false, | ||
fileBrowser: false, | ||
webid: true | ||
}) | ||
const bobPod = Solid.createServer({ | ||
root: path.join(__dirname, '/resources/accounts-scenario/bob'), | ||
sslKey: path.join(__dirname, '/keys/key.pem'), | ||
sslCert: path.join(__dirname, '/keys/cert.pem'), | ||
auth: 'oidc', | ||
dataBrowser: false, | ||
fileBrowser: false, | ||
webid: true | ||
}) | ||
|
||
function getBobFoo (alice, bob, done) { | ||
bob.get('/foo') | ||
.expect(401) | ||
.end((err, res) => { | ||
if (err) return done(err) | ||
expect(res).to.match(/META http-equiv="refresh"/) | ||
done() | ||
}) | ||
} | ||
|
||
function postBobDiscoverSignIn (alice, bob, done) { | ||
done() | ||
} | ||
|
||
function entersPasswordAndConsent (alice, bob, done) { | ||
done() | ||
} | ||
|
||
before(function (done) { | ||
parallel([ | ||
(cb) => { | ||
aliceServer = alicePod.listen(5000, cb) | ||
alice = supertest('https://localhost:5000') | ||
}, | ||
(cb) => { | ||
bobServer = bobPod.listen(5001, cb) | ||
bob = supertest('https://localhost:5001') | ||
} | ||
], done) | ||
}) | ||
|
||
after(function () { | ||
if (aliceServer) aliceServer.close() | ||
if (bobServer) bobServer.close() | ||
}) | ||
|
||
describe('APIs', () => { | ||
describe('/api/accounts/signin', () => { | ||
it('should complain if a URL is missing', (done) => { | ||
alice.post('/api/accounts/signin') | ||
.expect(400) | ||
.end(done) | ||
}) | ||
it('should complain if a URL is invalid', (done) => { | ||
alice.post('/api/accounts/signin') | ||
.send('webid=HELLO') | ||
.expect(400) | ||
.end(done) | ||
}) | ||
it('should return a 400 if endpoint doesn\'t have Link Headers', (done) => { | ||
nock('https://amazingwebsite.tld').intercept('/', 'OPTIONS').reply(200) | ||
alice.post('/api/accounts/signin') | ||
.send('webid=https://amazingwebsite.tld/') | ||
.expect(400) | ||
.end(done) | ||
}) | ||
it('should return a 400 if endpoint doesn\'t have oidc in the headers', (done) => { | ||
nock('https://amazingwebsite.tld').intercept('/', 'OPTIONS').reply(200, '', { | ||
'Link': function (req, res, body) { | ||
return '<https://oidc.amazingwebsite.tld>; rel="oidc.issuer"' | ||
}}) | ||
alice.post('/api/accounts/signin') | ||
.send('webid=https://amazingwebsite.tld/') | ||
.expect(302) | ||
.end((err, res) => { | ||
expect(res.header.location).to.eql('https://oidc.amazingwebsite.tld') | ||
done(err) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Auth workflow', () => { | ||
it.skip('step1: User tries to get /foo and gets 401 and meta redirect', (done) => { | ||
getBobFoo(alice, bob, done) | ||
}) | ||
|
||
it.skip('step2: User enters webId to signin', (done) => { | ||
postBobDiscoverSignIn(alice, bob, done) | ||
}) | ||
|
||
it.skip('step3: User enters password', (done) => { | ||
entersPasswordAndConsent(alice, bob, done) | ||
}) | ||
|
||
it.skip('entire flow', (done) => { | ||
waterfall([ | ||
(cb) => getBobFoo(alice, bob, cb), | ||
(cb) => postBobDiscoverSignIn(alice, bob, cb), | ||
(cb) => entersPasswordAndConsent(alice, bob, cb) | ||
], done) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.