Skip to content
Snippets Groups Projects
Commit 82b1dabd authored by Alexey Kuklin's avatar Alexey Kuklin
Browse files

Merge branch '390-device-management-ability-to-remove-device' into 'master'

Dispatch DeviceRevoked event to clients.

See merge request !28
parents 6b1beabe 249214fc
Branches
Tags
1 merge request!28Dispatch DeviceRevoked event to clients.
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# unused-packages = true # unused-packages = true
[[constraint]] [[constraint]]
branch = "master" branch = "390-device-management-ability-to-remove-device"
name = "code.vereign.com/code/restful-api" name = "code.vereign.com/code/restful-api"
[prune] [prune]
......
export const STATUS_DEVICE_REVOKED = "Device revoked";
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
} from '../utilities/signingUtilities'; } from '../utilities/signingUtilities';
import CryptoData from '../CryptoData'; import CryptoData from '../CryptoData';
import Identity from '../Identity'; import Identity from '../Identity';
import {STATUS_DEVICE_REVOKED} from '../constants/statuses';
const penpalMethods = require('../../temp/penpal-methods').default; const penpalMethods = require('../../temp/penpal-methods').default;
const WopiAPI = require('./wopiapi-iframe'); const WopiAPI = require('./wopiapi-iframe');
...@@ -193,6 +194,34 @@ function createEvent(actionId, type, payloads) { ...@@ -193,6 +194,34 @@ function createEvent(actionId, type, payloads) {
} }
} }
const destroyAuthentication = () => {
const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");
window.viamApi.setIdentity("");
window.viamApi.setSessionData("", "");
clearPinCodeTtl(authenticationPublicKey);
localStorage.removeItem("uuid");
localStorage.removeItem("token");
localStorage.removeItem("authenticatedIdentity");
window.currentlyAuthenticatedIdentity = null;
window.lastTimeGetProfile = 0;
};
const destroyIdentity = () => {
destroyAuthentication();
if (window.currentlyLoadedIdentity) {
const { publicKey } = window.currentlyLoadedIdentity.authentication;
delete window.loadedIdentities[publicKey];
window.currentlyLoadedIdentity = null;
destroyIdentityFromLocalStorage(publicKey);
}
};
window.loadedIdentities = {}; window.loadedIdentities = {};
window.wopiAPI = new WopiAPI(); window.wopiAPI = new WopiAPI();
window.collaboraApi = new CollaboraAPI(); window.collaboraApi = new CollaboraAPI();
...@@ -202,6 +231,8 @@ window.currentlyAuthenticatedIdentity = null; ...@@ -202,6 +231,8 @@ window.currentlyAuthenticatedIdentity = null;
window.currentlyLoadedIdentity = null; window.currentlyLoadedIdentity = null;
window.lastTimeGetProfile = 0; window.lastTimeGetProfile = 0;
let iframeParent = null;
const handleIdentityLogin = (identity, uuid, token) => { const handleIdentityLogin = (identity, uuid, token) => {
const { loadedIdentities, viamApi } = window; const { loadedIdentities, viamApi } = window;
const { publicKey } = identity.authentication; const { publicKey } = identity.authentication;
...@@ -219,10 +250,22 @@ function executeRestfulFunction(type, that, fn, ...args) { ...@@ -219,10 +250,22 @@ function executeRestfulFunction(type, that, fn, ...args) {
const { currentlyAuthenticatedIdentity, viamApi, currentlyLoadedIdentity } = window; const { currentlyAuthenticatedIdentity, viamApi, currentlyLoadedIdentity } = window;
return new Penpal.Promise(executeResult => { return new Penpal.Promise(executeResult => {
fn.apply(that, args).then((response) => { fn.apply(that, args).then(async (response) => {
const identity = currentlyAuthenticatedIdentity || currentlyLoadedIdentity; const identity = currentlyAuthenticatedIdentity || currentlyLoadedIdentity;
if (type === "private" && identity && response.data.code === "400" && response.data.status === "Bad session") { const { code, status } = response.data;
// Destroy local storage in case device was revoked
if (type === "private" && code === "401" && status === STATUS_DEVICE_REVOKED) {
destroyIdentity();
const event = createEvent("", "DeviceRevoked");
iframeParent.onEvent(event);
return executeResult(response.data);
}
if (type === "private" && identity && code === "400" && status === "Bad session") {
viamApi.identityLogin("previousaddeddevice") viamApi.identityLogin("previousaddeddevice")
.then((response) => { .then((response) => {
if (response.data.code === "200") { if (response.data.code === "200") {
...@@ -696,17 +739,7 @@ const connection = Penpal.connectToParent({ ...@@ -696,17 +739,7 @@ const connection = Penpal.connectToParent({
window.viamApi.identityLogout window.viamApi.identityLogout
); );
window.viamApi.setIdentity(""); destroyAuthentication();
window.viamApi.setSessionData("", "");
clearPinCodeTtl(authenticationPublicKey);
localStorage.removeItem("uuid");
localStorage.removeItem("token");
localStorage.removeItem("authenticatedIdentity");
delete window.loadedIdentities[authenticationPublicKey];
window.currentlyLoadedIdentity = null;
window.currentlyAuthenticatedIdentity = null;
window.lastTimeGetProfile = 0;
return identityLogoutResponse; return identityLogoutResponse;
}, },
...@@ -1041,6 +1074,8 @@ const connection = Penpal.connectToParent({ ...@@ -1041,6 +1074,8 @@ const connection = Penpal.connectToParent({
}); });
connection.promise.then(parent => { connection.promise.then(parent => {
iframeParent = parent;
if (!navigator.cookieEnabled) { if (!navigator.cookieEnabled) {
console.warn("Cookie disabled. Can't start library."); console.warn("Cookie disabled. Can't start library.");
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment