2020-04-17 19:42:35 +02:00
|
|
|
import kdbxweb from 'kdbxweb';
|
|
|
|
|
|
|
|
let newOAuthSession;
|
|
|
|
|
|
|
|
function createOAuthSession() {
|
|
|
|
const session = newOAuthSession;
|
|
|
|
|
|
|
|
const state = kdbxweb.ByteUtils.bytesToHex(kdbxweb.Random.getBytes(64));
|
|
|
|
const codeVerifier = kdbxweb.ByteUtils.bytesToHex(kdbxweb.Random.getBytes(50));
|
|
|
|
|
|
|
|
const codeVerifierBytes = kdbxweb.ByteUtils.arrayToBuffer(
|
|
|
|
kdbxweb.ByteUtils.stringToBytes(codeVerifier)
|
|
|
|
);
|
2020-06-01 16:53:51 +02:00
|
|
|
kdbxweb.CryptoEngine.sha256(codeVerifierBytes).then((hash) => {
|
2020-04-17 19:42:35 +02:00
|
|
|
const codeChallenge = kdbxweb.ByteUtils.bytesToBase64(hash)
|
|
|
|
.replace(/\+/g, '-')
|
|
|
|
.replace(/\//g, '_')
|
|
|
|
.replace(/=/g, '');
|
|
|
|
|
|
|
|
newOAuthSession = {
|
|
|
|
state,
|
|
|
|
codeChallenge,
|
|
|
|
codeVerifier
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
newOAuthSession = null;
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { createOAuthSession };
|