Skip to content

Commit e893f99

Browse files
committed
Merge branch 'solid-client-authn-integration' of https://github.com/solid/node-solid-server
2 parents 5de2665 + e5d209a commit e893f99

11 files changed

Lines changed: 3336 additions & 316 deletions

File tree

common/js/auth-buttons.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global location, alert, solid */
22
/* Provide functionality for authentication buttons */
33

4-
(({ auth }) => {
4+
((SessionManager) => {
55
// Wire up DOM elements
66
const [
77
loginButton,
@@ -22,38 +22,55 @@
2222
logoutButton.addEventListener('click', logout)
2323
registerButton.addEventListener('click', register)
2424

25-
// Track authentication status and update UI
26-
auth.trackSession(session => {
27-
const loggedIn = !!session
28-
const isOwner = loggedIn && new URL(session.webId).origin === location.origin
25+
function onSessionChange(sessionInfo) {
26+
const loggedIn = sessionInfo.isLoggedIn
27+
const isOwner = loggedIn && new URL(sessionInfo.webId).origin === location.origin
2928
loginButton.classList.toggle('hidden', loggedIn)
3029
logoutButton.classList.toggle('hidden', !loggedIn)
3130
registerButton.classList.toggle('hidden', loggedIn)
3231
accountSettings.classList.toggle('hidden', !isOwner)
3332
loggedInContainer.classList.toggle('hidden', !loggedIn)
34-
if (session) {
35-
profileLink.href = session.webId
36-
profileLink.innerText = session.webId
33+
if (sessionInfo) {
34+
profileLink.href = sessionInfo.webId
35+
profileLink.innerText = sessionInfo.webId
3736
}
38-
})
37+
}
38+
39+
const session = new SessionManager.Session(
40+
{
41+
clientAuthentication: solidClientAuthentication.getClientAuthenticationWithDependencies(
42+
{}
43+
),
44+
},
45+
"mySession"
46+
);
47+
48+
const authCode = new URL(window.location.href).searchParams.get("code")
49+
if (authCode) {
50+
// Being redirected after requesting a token
51+
session
52+
.handleIncomingRedirect(new URL(window.location.href))
53+
.then((sessionInfo) => {
54+
onSessionChange(sessionInfo)
55+
});
56+
} else {
57+
onSessionChange(session.info)
58+
}
3959

4060
// Log the user in on the client and the server
4161
async function login () {
42-
const session = await auth.popupLogin()
43-
if (session) {
44-
// Make authenticated request to the server to establish a session cookie
45-
const { status } = await auth.fetch(location, { method: 'HEAD' })
46-
if (status === 401) {
47-
alert(`Invalid login.\n\nDid you set ${session.idp} as your OIDC provider in your profile ${session.webId}?`)
48-
await auth.logout()
49-
}
50-
location.reload()
51-
}
62+
// TODO: This should be made to look nicer.
63+
const thisUrl = new URL(window.location.href).origin
64+
const issuer = prompt("Enter an issuer", thisUrl)
65+
session.login({
66+
redirectUrl: new URL(window.location.href),
67+
oidcIssuer: new URL(issuer),
68+
});
5269
}
5370

5471
// Log the user out from the client and the server
5572
async function logout () {
56-
await auth.logout()
73+
await session.logout()
5774
location.reload()
5875
}
5976

@@ -62,4 +79,4 @@
6279
const registration = new URL('/register', location)
6380
location.href = registration
6481
}
65-
})(solid)
82+
})(solidClientAuthentication)

default-templates/server/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h2>Server info</h2>
4949
</dl>
5050
</section>
5151
</div>
52-
<script src="/common/js/solid-auth-client.bundle.js"></script>
52+
<script src="/common/js/solid-client-authn.bundle.js"></script>
5353
<script src="/common/js/auth-buttons.js"></script>
5454
</body>
5555
</html>

default-views/auth/login-required.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
</div>
3030
</div>
31-
<script src="/common/js/solid-auth-client.bundle.js"></script>
31+
<script src="/common/js/solid-client-authn.bundle.js"></script>
3232
<script src="/common/js/auth-buttons.js"></script>
3333
</body>
3434
</html>

default-views/auth/no-permission.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</div>
2424
</div>
2525
</div>
26-
<script src="/common/js/solid-auth-client.bundle.js"></script>
26+
<script src="/common/js/solid-client-authn.bundle.js"></script>
2727
<script src="/common/js/auth-buttons.js"></script>
2828
</body>
2929
</html>

lib/create-app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function createApp (argv = {}) {
6868
// Serve the public 'common' directory (for shared CSS files, etc)
6969
app.use('/common', express.static(path.join(__dirname, '../common')))
7070
app.use('/', express.static(path.dirname(require.resolve('mashlib/dist/databrowser.html')), { index: false }))
71-
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js')
72-
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js.map')
71+
routeResolvedFile(app, '/common/js/', '@inrupt/solid-client-authn-browser/browserDist/solid-client-authn.bundle.js')
7372
app.use('/.well-known', express.static(path.join(__dirname, '../common/well-known')))
7473

7574
// Serve bootstrap from it's node_module directory

0 commit comments

Comments
 (0)