Skip to content

Commit ade86c0

Browse files
Simplify usage
1 parent d2370b3 commit ade86c0

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
A Javascript authentication plugin for
66
[`solid-client`](https://github.com/solid/solid-client) based on OAuth2/OpenID
77
Connect.
8+
9+
This is an Authentication helper library that wraps an OpenID Connect (OIDC)
10+
Relying Party library, [`oidc-rp`](https://github.com/anvilresearch/oidc-rp).
11+
It is meant to be used in browser-side applications, as part of `solid-client`.

‎demo/index.html‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<title>Solid Auth Test Page</title>
6+
<title>Solid Auth Demo App</title>
77
<!-- Bootstrap CSS and Theme for demo purposes -->
88
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
99
<!-- Solid Demo template/stylesheet -->
@@ -17,7 +17,8 @@
1717
<h3>Solid Auth Demo Page</h3>
1818
</div>
1919
<div class="demo-section" style="width: 100%;">
20-
<p>Option 1: Login on the same page (in iframe), allow main window redirect.</p>
20+
<p>Login Option 1: Login on the same page (in iframe), allow main window
21+
redirect.</p>
2122
<iframe id="solidLogin" src="login_iframe_inline.html" seamless style="width: 100%; border: none; margin-top: 1em;"></iframe>
2223
</div>
2324
<div class="demo-section">
@@ -27,13 +28,19 @@ <h5>App body</h5>
2728
</div>
2829
</body>
2930
<script>
30-
var auth = new SolidAuth()
31+
var solid = { auth: new SolidAuth() }
3132

32-
document.addEventListener('DOMContentLoaded', function () { init() })
33-
34-
function init () {
35-
window.addEventListener('message', auth.onMessage.bind(auth))
36-
auth.detectAuthCallback()
37-
}
33+
// Using a standard "document loaded" event listener
34+
// (equivalent to jQuery's $(document).ready()
35+
document.addEventListener('DOMContentLoaded', function () {
36+
// Init the solid auth helper, inject whatever behavior you want to happen
37+
// when authentication succeeds.
38+
solid.auth.init({
39+
onLoginSuccess: function (webId, accessToken) {
40+
console.log('onLoginSuccess() callback! webId: ', webId,
41+
'access_token: ', accessToken)
42+
}
43+
})
44+
})
3845
</script>
3946
</html>

‎demo/login_iframe_inline.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!doctype html>
22
<html lang="en">
33
<head>
4+
<meta charset="utf-8">
45
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
56
<script type="text/javascript">
67
var parent, pageUrl

‎src/index.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ class ClientAuthOIDC {
118118
return state
119119
}
120120

121+
init (callbacks = {}) {
122+
this.callbacks = callbacks
123+
window.addEventListener('message', this.onMessage.bind(this))
124+
this.detectAuthCallback()
125+
}
126+
121127
keyByProvider (providerUri = this.providerUri) {
122128
return `oidc.rp.by-provider.${providerUri}`
123129
}

0 commit comments

Comments
 (0)