Files
zulip-desktop/app/renderer/js/utils/auth-util.ts
ViPuL 49b29bfed6 auth: Move social login process to browser.
Moves the social login to browser since there
was no way to verify the authencity of the
auth process for a custom server and to
prevent phishing attacks.

Fixes #849.

Co-authored-by: Kanishk Kakar <kanishk.kakar@gmail.com>
2020-02-25 20:05:27 +05:30

37 lines
848 B
TypeScript

import { remote } from 'electron';
import cryptoRandomString = require('crypto-random-string');
import ConfigUtil = require('./config-util');
const { shell } = remote;
class AuthUtil {
openInBrowser = (link: string) => {
const otp = cryptoRandomString({length: 64});
ConfigUtil.setConfigItem('desktopOtp', otp);
shell.openExternal(`${link}?desktop_flow_otp=${otp}`);
};
xorStrings = (a: string, b: string): string => {
if (a.length === b.length) {
return a
.split('')
.map((char, i) => (parseInt(a[i], 16) ^ parseInt(b[i], 16)).toString(16))
.join('')
.toUpperCase();
} else {
return '';
}
};
hexToAscii = (hex: string) => {
let ascii = '';
for (let i = 0; i < hex.length; i += 2) {
ascii += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return ascii;
};
}
export = new AuthUtil();