This repository was archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaxcms-jwt.php
More file actions
120 lines (116 loc) · 4.2 KB
/
haxcms-jwt.php
File metadata and controls
120 lines (116 loc) · 4.2 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
include_once '../../../system/lib/bootstrapHAX.php';
include_once $HAXCMS->configDirectory . '/config.php';
$appSettings = $HAXCMS->appJWTConnectionSettings();
?>
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../jwt-login/jwt-login.html">
<!--
`haxcms-jwt`
a simple element to check for and fetch JWTs
@demo demo/index.html
@microcopy - the mental model for this element
- jwt - a json web token which is an encrypted security token to talk
-->
<dom-module id="haxcms-jwt">
<template>
<style>
:host {
display: block;
}
</style>
<jwt-login id="jwt" url="[[jwtLoginLocation]]" url-logout="[[jwtLogoutLocation]]" jwt="{{jwt}}"></jwt-login>
</template>
<script>
window.appSettings = <?php print json_encode($appSettings); ?>;
Polymer({
is: 'haxcms-jwt',
properties: {
/**
* Location of what endpoint to hit for
*/
jwtLoginLocation: {
type: String,
value: window.appSettings.login,
},
/**
* Location of what endpoint to hit for logging out
*/
jwtLogoutLocation: {
type: String,
value: window.appSettings.logout,
},
/**
* JSON Web token, it'll come from a global call if it's available
*/
jwt: {
type: String,
},
},
/**
* Attached life cycle
*/
created: function () {
document.body.addEventListener('jwt-token', this._jwtTokenFired.bind(this));
document.body.addEventListener('json-outline-schema-active-item-changed', this.initialItem.bind(this));
document.body.addEventListener('json-outline-schema-changed', this.initialManifest.bind(this));
document.body.addEventListener('json-outline-schema-active-body-changed', this.initialBody.bind(this));
},
initialItem: function (e) {
this.__item = e.detail;
},
initialManifest: function (e) {
this.__manifest = e.detail;
},
initialBody: function (e) {
this.__body = e.detail;
},
/**
* JWT token fired, let's capture it
*/
_jwtTokenFired: function (e) {
this.jwt = e.detail;
},
/**
* Attached life cycle
*/
attached: function () {
if (this.jwt != null) {
// attempt to dynamically import the hax cms site editor
// which will appear to be injecting into the page
// but because of this approach it should be non-blocking
try {
this.importHref(this.resolveUrl('haxcms-site-editor.html'), (e) => {
let haxCmsSiteEditorElement = document.createElement('haxcms-site-editor');
haxCmsSiteEditorElement.jwt = this.jwt;
haxCmsSiteEditorElement.savePagePath = window.appSettings.savePagePath;
haxCmsSiteEditorElement.saveManifestPath = window.appSettings.saveManifestPath;
haxCmsSiteEditorElement.saveOutlinePath = window.appSettings.saveOutlinePath;
haxCmsSiteEditorElement.publishPath = window.appSettings.publishPath;
haxCmsSiteEditorElement.appStore = window.appSettings.appStore;
// pass along the initial state management stuff that may be missed
// based on timing on the initial setup
if (typeof this.__item !== typeof undefined) {
haxCmsSiteEditorElement.activeItem = this.__item;
}
if (typeof this.__manifest !== typeof undefined) {
console.log('well it was here');
haxCmsSiteEditorElement.manifest = this.__manifest;
}
if (typeof this.__body !== typeof undefined) {
haxCmsSiteEditorElement.__body = this.__body;
}
Polymer.cmsSiteEditor.instance.haxCmsSiteEditorElement = haxCmsSiteEditorElement;
Polymer.cmsSiteEditor.instance.appendTarget.appendChild(haxCmsSiteEditorElement);
}, (e) => {
//import failed
});
}
catch (err) {
// error in the event this is a double registration
}
}
},
});
</script>
</dom-module>