Skip to content

Commit a715d9a

Browse files
authored
fix(apple-sign-in): SHA256 hash nonce in request (#241)
1 parent 52dd7f4 commit a715d9a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/apple-sign-in/index.ios.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ function randomNonce(length: number) {
6363
return result;
6464
}
6565

66+
function sha256Hash(input: string): string {
67+
const sha256buffer = CC_SHA256(interop.handleof(NSString.stringWithString(input).UTF8String), input.length, interop.alloc(input.length));
68+
let inputHashed = '';
69+
for (let i = 0; i < input.length; i++) {
70+
inputHashed += parseInt(sha256buffer[i], 10).toString(16).padStart(2, '0');
71+
}
72+
return inputHashed;
73+
}
74+
6675
export class SignIn {
6776
static #controller: ASAuthorizationController;
6877
static #delegate: ASAuthorizationControllerDelegate;
@@ -100,10 +109,10 @@ export class SignIn {
100109

101110
if (options?.useNonce) {
102111
if (options.nonce) {
103-
request.nonce = options.nonce;
112+
request.nonce = sha256Hash(options.nonce);
104113
} else {
105114
const nonce = randomNonce(32);
106-
request.nonce = nonce;
115+
request.nonce = sha256Hash(nonce);
107116
(this.#delegate as any)._options.nonce = nonce;
108117
}
109118
}

0 commit comments

Comments
 (0)