Skip to content

Commit d2370b3

Browse files
Implement login via inline iframe
1 parent 90dbb7a commit d2370b3

8 files changed

Lines changed: 338 additions & 27 deletions

File tree

‎.babelrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
# Build dirs
36+
lib
37+
dist

‎demo/demo.css‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
margin-bottom: 3em;
3+
}
4+
.demo-section {
5+
margin-top: 2em;
6+
border-top: 1px solid gray;
7+
}

‎demo/index.html‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Solid Auth Test Page</title>
7+
<!-- Bootstrap CSS and Theme for demo purposes -->
8+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
9+
<!-- Solid Demo template/stylesheet -->
10+
<link rel="stylesheet" href="./demo.css" />
11+
<!-- Relying Party lib, exports a global var: SolidAuth -->
12+
<script src="../dist/solid-auth-oidc.min.js"></script>
13+
</head>
14+
<body>
15+
<div class="container">
16+
<div>
17+
<h3>Solid Auth Demo Page</h3>
18+
</div>
19+
<div class="demo-section" style="width: 100%;">
20+
<p>Option 1: Login on the same page (in iframe), allow main window redirect.</p>
21+
<iframe id="solidLogin" src="login_iframe_inline.html" seamless style="width: 100%; border: none; margin-top: 1em;"></iframe>
22+
</div>
23+
<div class="demo-section">
24+
<h5>App body</h5>
25+
<p>The rest of the app goes here</p>
26+
</div>
27+
</div>
28+
</body>
29+
<script>
30+
var auth = new SolidAuth()
31+
32+
document.addEventListener('DOMContentLoaded', function () { init() })
33+
34+
function init () {
35+
window.addEventListener('message', auth.onMessage.bind(auth))
36+
auth.detectAuthCallback()
37+
}
38+
</script>
39+
</html>

‎demo/login_iframe_inline.html‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
5+
<script type="text/javascript">
6+
var parent, pageUrl
7+
window.addEventListener('load', function () { init() });
8+
9+
function init () {
10+
parent = window.parent
11+
// console.log('Frame parent: ', parent)
12+
pageUrl = parent.window.location.href
13+
// console.log('Parent url: ', pageUrl)
14+
// console.log('Parent origin: ', parent.window.location.origin)
15+
// console.log('iFrame origin: ', window.location.origin)
16+
// var pageOrigin = opener.location.origin;
17+
// opener.postMessage(pageUrl, pageOrigin);
18+
initEvents()
19+
}
20+
function initButton(id, action) {
21+
document.getElementById(id).addEventListener('click', action)
22+
}
23+
function initEvents () {
24+
initButton('local_provider',
25+
function () { selectProvider('https://ldnode.local:8443') })
26+
initButton('db_provider',
27+
function () { selectProvider('https://databox2.com') })
28+
}
29+
function selectProvider (providerUri) {
30+
console.log('Provider selected: ', providerUri)
31+
var message = {
32+
event_type: 'providerSelected',
33+
value: providerUri
34+
}
35+
parent.postMessage(message, parent.window.location.origin)
36+
}
37+
function setField (id, value) {
38+
var field = document.getElementById(id)
39+
if (field) {
40+
field.innerHTML = value
41+
}
42+
}
43+
function hide (id) {
44+
document.getElementById(id).className = 'hidden'
45+
}
46+
function show (id) {
47+
var div = document.getElementById(id)
48+
div.className = div.className.replace('hidden', '')
49+
}
50+
</script>
51+
</head>
52+
<body>
53+
<div class="container">
54+
<div class="row">
55+
<div class="col-sm-2"><strong>Login with:</strong></div>
56+
<div class="col-sm-1">
57+
<button type="button" class="btn btn-xs btn-primary" id="local_provider">
58+
localhost
59+
</button>
60+
</div>
61+
<div class="col-sm-2">
62+
<button type="button" class="btn btn-xs btn-primary" id="db_provider">
63+
databox2.com
64+
</button>
65+
</div>
66+
<div class="col-sm-7">
67+
or custom:
68+
<input type="text" id="custom_provider" value="" placeholder="databox.me" />
69+
</div>
70+
</div>
71+
</div>
72+
</body>
73+
</html>

‎package.json‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"description": "Authentication library for Solid client based on OAuth2/OpenID Connect",
88
"main": "./lib/index.js",
99
"files": [
10-
"index.js",
11-
"config-default.js"
10+
"lib",
11+
"dist"
1212
],
1313
"scripts": {
1414
"build": "npm run build-lib",
15+
"build-dist": "webpack --progress --colors --optimize-occurrence-order --optimize-dedupe",
1516
"build-lib": "babel src -d lib",
17+
"dist": "npm run build && npm run build-dist",
1618
"postversion": "git push --follow-tags",
1719
"prepublish": "npm run build && npm run test",
1820
"preversion": "npm test",
@@ -52,11 +54,17 @@
5254
"devDependencies": {
5355
"babel-cli": "^6.18.0",
5456
"babel-core": "^6.21.0",
57+
"babel-loader": "^6.2.5",
5558
"babel-preset-es2015": "^6.18.0",
5659
"standard": "^5.4.1",
57-
"tape": "^4.6.3"
60+
"tape": "^4.6.3",
61+
"webpack": "^1.14.0"
5862
},
5963
"standard": {
60-
"globals": []
64+
"globals": [
65+
"localStorage",
66+
"URL",
67+
"URLSearchParams"
68+
]
6169
}
6270
}

0 commit comments

Comments
 (0)