Skip to content

Commit a1810d3

Browse files
Merge pull request #769 from solid/feature/solid-auth-client-v2.2
Use latest solid-auth-client
2 parents a52a062 + 6809e0e commit a1810d3

File tree

5 files changed

+44
-67
lines changed

5 files changed

+44
-67
lines changed

default-templates/new-account/index.html

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -65,65 +65,18 @@ <h1>Apps</h1>
6565
</div>
6666
</section>
6767
</div>
68-
</body>
6968
<script src="/common/js/solid-auth-client.bundle.js"></script>
7069
<script type="text/javascript">
71-
const popupUri = window.location.origin + '/common/popup.html'
72-
const stateData = {
73-
session: null
74-
}
75-
const state = new Proxy(stateData, {
76-
set: (obj, prop, value) => {
77-
obj[prop] = value
78-
render()
79-
}
80-
})
81-
82-
function main() {
83-
// Render the session state
84-
SolidAuthClient
85-
.currentSession()
86-
.then(saveSession)
87-
.then(render)
88-
89-
// Add event listeners
90-
const actionButton = sessionActionButton()
91-
actionButton.addEventListener('click', takeSessionAction)
92-
}
93-
94-
function saveSession(session) {
95-
state.session = session
96-
return session
97-
}
70+
const button = document.getElementById('session-action')
71+
let loggedIn = false
9872

99-
function takeSessionAction() {
100-
const { session } = state
101-
const loggedIn = !!session
102-
if (loggedIn) {
103-
SolidAuthClient
104-
.logout()
105-
.then(saveSession)
106-
} else {
107-
SolidAuthClient
108-
.popupLogin({ popupUri })
109-
.then(saveSession)
110-
}
111-
}
112-
113-
function render() {
114-
const { session } = state
115-
const actionButton = sessionActionButton()
116-
if (!session) {
117-
actionButton.innerText = 'Log in'
118-
} else {
119-
actionButton.innerText = 'Log out'
120-
}
121-
}
122-
123-
function sessionActionButton() {
124-
return document.getElementById('session-action')
125-
}
73+
solid.auth.trackSession(session => {
74+
loggedIn = !!session
75+
button.innerText = loggedIn ? 'Log out' : 'Log in'
76+
})
12677

127-
document.addEventListener('DOMContentLoaded', main)
78+
button.addEventListener('click', () =>
79+
loggedIn ? solid.auth.logout() : solid.auth.popupLogin())
12880
</script>
81+
</body>
12982
</html>

default-views/auth/login-required.hbs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<title>Log in</title>
77
<link rel="stylesheet" href="/common/css/bootstrap.min.css">
8-
<script src="/common/js/solid-auth-client.bundle.js"></script>
98
</head>
109
<body>
1110
<div class="container">
@@ -20,17 +19,16 @@
2019
<button class="btn btn-primary" onclick="register()">Register</button>
2120
</div>
2221
</div>
22+
<script src="/common/js/solid-auth-client.bundle.js"></script>
2323
<script>
2424
async function login() {
25-
// Log in through the popup
26-
const popupUri = '/common/popup.html'
27-
const session = await SolidAuthClient.popupLogin({ popupUri })
25+
const session = await solid.auth.popupLogin()
2826
if (session) {
2927
// Make authenticated request to the server to establish a session cookie
30-
const { status } = await SolidAuthClient.fetch(location)
28+
const { status } = await solid.auth.fetch(location)
3129
if (status === 401) {
3230
alert(`Invalid login.\n\nDid you set ${session.idp} as your OIDC provider in your profile ${session.webId}?`);
33-
await SolidAuthClient.logout();
31+
await solid.auth.logout()
3432
}
3533
// Now that we have a cookie, reload to display the authenticated page
3634
location.reload()

lib/api/authn/webid-oidc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ function middleware (oidc) {
9494
['/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js.map']
9595
]
9696
authAssets.map(([path, file]) => routeResolvedFile(router, path, file))
97+
// Redirect for .well-known login popup location
98+
router.get('/.well-known/solid/login',
99+
(req, res) => res.redirect('/common/popup.html'))
97100

98101
// Initialize the OIDC Identity Provider routes/api
99102
// router.get('/.well-known/openid-configuration', discover.bind(provider))

package-lock.json

Lines changed: 27 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"rdflib": "^0.17.0",
6565
"recursive-readdir": "^2.1.0",
6666
"rimraf": "^2.5.0",
67-
"solid-auth-client": "^2.1.1",
67+
"solid-auth-client": "^2.2.1-rc.0",
6868
"solid-namespace": "^0.1.0",
6969
"solid-permissions": "^0.6.0",
7070
"solid-ws": "^0.2.3",

0 commit comments

Comments
 (0)