Skip to content

Commit 6a9db46

Browse files
committed
webAuth [nfc]: Extract implementation into generateRandomToken function.
In an upcoming commit, we'll need to generate a random token (the same implementation is fine), but without the OTP semantics.
1 parent cc8b569 commit 6a9db46

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/start/webAuth.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import { base64ToHex, hexToAscii, xorHexStrings } from '../utils/encoding';
2727
https://chat.zulip.org/#narrow/stream/16-desktop/topic/desktop.20app.20OAuth/near/803919
2828
*/
2929

30-
// Generate a one time pad (OTP) which the server XORs the API key with
31-
// in its response to protect against credentials intercept
32-
export const generateOtp = async (): Promise<string> => {
30+
export const generateRandomToken = async (): Promise<string> => {
3331
if (Platform.OS === 'android') {
3432
return new Promise((resolve, reject) => {
3533
NativeModules.RNSecureRandom.randomBase64(32, (err, result) => {
@@ -45,6 +43,10 @@ export const generateOtp = async (): Promise<string> => {
4543
}
4644
};
4745

46+
// Generate a one time pad (OTP) which the server XORs the API key with
47+
// in its response to protect against credentials intercept
48+
export const generateOtp = async (): Promise<string> => generateRandomToken();
49+
4850
export const openBrowser = (url: string, otp: string) => {
4951
openLink(`${url}?mobile_flow_otp=${otp}`);
5052
};

0 commit comments

Comments
 (0)