-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathf-jwt-decode.html
More file actions
43 lines (36 loc) · 996 Bytes
/
f-jwt-decode.html
File metadata and controls
43 lines (36 loc) · 996 Bytes
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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../jwt-decode/jwt-decode.html">
<link rel="import" href="./finterface-jwt-decoder.html">
<!--
[auth0/jwt-decode](https://github.com/auth0/jwt-decode) wrapper element.
Example:
<f-jwt-decode token="..." value="{{decoded}}"></f-jwt-decode>
<p>[[decoded]]</p>
@element jwt-decode
@demo demo/index.html
-->
<dom-module id="f-jwt-decode">
<script>
Polymer({
is: 'f-jwt-decode',
behaviors: [FInterface.JwtDecoder],
observers: ['_tokenChanged(token)'],
/**
* Decode JWT
*
* @param {string} a full JWT
* @return {Object} claims
*/
decode: function(token) {
if (!token) return null;
const decode = typeof global !== 'undefined'
? global.window.jwt_decode
: window.jwt_decode;
return decode(token);
},
_tokenChanged: function(newValue) {
this.value = this.decode(newValue);
}
});
</script>
</dom-module>