-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
43 lines (39 loc) · 1.33 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FamilySearch Auth</title>
</head>
<body>
<h1>FamilySearch Authenticator</h1>
<p>Authentication example using FamilySearch OpenId Connect API</p>
<a onclick="fs.oauthRedirect()" href="javascript:void(0)">Login</a>
<div id="info" style="display: none;">
<h3>JWT Info</h3>
<pre id="jwt"></pre>
<h3>User Info</h3>
<pre id="user"></pre>
</div>
<script src="https://unpkg.com/fs-js-lite@latest/dist/FamilySearch.min.js"></script>
<script type="text/javascript">
var fs = new FamilySearch({
environment: 'production',
appKey: 'a02j000000KTRjpAAH',
redirectUri: 'https://misbach.github.io/fs-auth/'
// redirectUri: 'http://localhost:5000'
});
// Finish oauth flow by obtaining access_token
fs.oauthResponse(function() {
document.getElementById("info").removeAttribute("style");
// Decode the OpenID Connect JWT
var token = JSON.parse(atob(fs.jwt.split('.')[1]));
document.getElementById("jwt").innerHTML = JSON.stringify(token).replace(/,/g,",\n");
// FamilySearch API Call (Get User Data)
fs.get('/platform/users/current', function(error, response) {
let user = JSON.stringify(response.data.users[0]);
document.getElementById("user").innerHTML = user.replace(/,/g,",\n");
});
});
</script>
</body>
</html>