-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth0-delegate.html
65 lines (60 loc) · 1.72 KB
/
auth0-delegate.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="auth0.html">
<dom-module id="auth0-delegate">
<template>
</template>
<script>
class Auth0Delegate extends Polymer.Element {
static get is() { return 'auth0-delegate'; }
static get properties() {
return {
idToken: {
type: String
},
options: {
type: Object
},
clientId: {
type: String
},
domain: {
type: String
},
delegateToken: {
type: String,
readOnly: true,
notify: true,
value: ''
}
}
}
static get observers() {
return [
'_getDelegateToken(domain, clientId, idToken, options)'
]
}
_getDelegateToken(domain, clientId, idToken, options) {
if(clientId !== undefined && domain !== undefined && options !== undefined && idToken !== undefined) {
var auth = new auth0.Authentication({
domain: this.domain,
clientID: this.clientId
});
var options = {
id_token: this.idToken,
apiType: this.options.api,
scope: this.options.scope,
target: this.clientId,
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer'
};
// Make a call to the Auth0 '/delegate'
auth.delegation(options, function(err, result) {
if(!err) {
this._setDelegateToken(result.idToken);
}
}.bind(this));
}
}
}
customElements.define(Auth0Delegate.is, Auth0Delegate);
</script>
</dom-module>