Skip to content

Commit 8ee9e08

Browse files
authored
Merge pull request #34 from Lg0gs/code-verifier-generator
chore: generate code verifier
2 parents 5ff89c0 + 9bed142 commit 8ee9e08

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![banner](https://files.oaiusercontent.com/file-AcMf2jF9MDCjSTBtbp1kdW?se=2025-02-08T07:41:09Z&sp=r&sv=2024-08-04&sr=b&rscc=max-age=604800,%20immutable,%20private&rscd=attachment;%20filename=046f1457-edf3-4c02-a39a-885a0c3fe3a0.webp&sig=miu/LRKo7l4fcg9A/Oe6zxv234a2eJQUVzfnxtskmz4=)
22

3-
[![License](https://img.shields.io/npm/l/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok?tab=MIT-1-ov-file#readme) [![version](https://img.shields.io/github/package-json/version/Lg0gs/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok/releases) [![downloads](https://img.shields.io/npm/dm/react-native-tiktok)](https://www.npmjs.com/package/react-native-tiktok) ![size](https://img.shields.io/npm/unpacked-size/react-native-tiktok?color=F75307) [![stars](https://img.shields.io/github/stars/Lg0gs/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok/stargazers)
3+
[![License](https://img.shields.io/npm/l/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok?tab=MIT-1-ov-file#readme) [![version](https://img.shields.io/github/package-json/version/Lg0gs/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok/releases) [![downloads](https://img.shields.io/npm/dm/react-native-tiktok)](https://www.npmjs.com/package/react-native-tiktok) ![size](https://img.shields.io/npm/unpacked-size/react-native-tiktok?color=F75307) [![stars](https://img.shields.io/github/stars/Lg0gs/react-native-tiktok)](https://github.com/Lg0gs/react-native-tiktok/stargazers)
44

55
Get authorized and fetch user profile
66

@@ -123,10 +123,10 @@ import { authorize } from 'react-native-tiktok';
123123

124124
authorize({
125125
redirectURI: '<YOUR_REDIRECT_URL>', // redirectURI is your universal link
126-
codeVerifier: '', // Only for Android
127-
callback: (authCode) => {
126+
callback: (authCode, codeVerifier) => {
128127
// immediately invokes callback function as soon as operation is completed
129-
console.log(authCode);
128+
// codeVerifier is returned only on Android
129+
console.log(authCode, codeVerifier);
130130
},
131131
});
132132
```

android/src/main/java/com/tiktok/TiktokModule.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
1010
import com.facebook.react.bridge.ReactMethod
1111
import com.tiktok.open.sdk.auth.AuthApi
1212
import com.tiktok.open.sdk.auth.AuthRequest
13+
import com.tiktok.open.sdk.auth.utils.PKCEUtils
1314

1415
class TiktokModule(reactContext: ReactApplicationContext) :
1516
ReactContextBaseJavaModule(reactContext) {
1617

1718
private var authApi: AuthApi? = null
1819
private var redirectUrl: String = ""
20+
private var codeVerifier = PKCEUtils.generateCodeVerifier()
1921
private var callback: Callback? = null
2022

2123
init {
@@ -25,7 +27,7 @@ class TiktokModule(reactContext: ReactApplicationContext) :
2527
if (it.authErrorDescription != null) {
2628
Toast.makeText(reactApplicationContext, it.authErrorDescription, Toast.LENGTH_LONG).show()
2729
} else {
28-
callback?.invoke(it.authCode)
30+
callback?.invoke(it.authCode, codeVerifier)
2931
}
3032
}
3133
}
@@ -41,7 +43,7 @@ class TiktokModule(reactContext: ReactApplicationContext) :
4143
}
4244

4345
@ReactMethod
44-
fun authorize(redirectURI: String, callback: Callback, codeVerifier: String) {
46+
fun authorize(redirectURI: String, callback: Callback) {
4547
this.redirectUrl = redirectURI
4648
this.callback = callback
4749

example/src/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ export default function App() {
66
useEffect(() => {
77
authorize({
88
redirectURI: '<YOUR_REDIRECT_URL>',
9-
callback: (authCode) => {
10-
console.log(authCode);
9+
callback: (authCode, codeVerifier) => {
10+
console.log(authCode, codeVerifier);
1111
},
12-
codeVerifier: 'sQ6tdXroCIy746YBgCsNL9DqLJbwE88bBm-PzmB0BTc',
1312
});
1413
}, []);
1514

src/index.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import { NativeModules, Platform } from 'react-native';
1+
import { NativeModules } from 'react-native';
22

33
type Props = {
44
redirectURI: string;
5-
callback(authCode: string): void;
6-
codeVerifier?: string;
5+
callback(authCode: string, codeVerifier?: string): void;
76
};
87

98
const Tiktok = NativeModules.Tiktok;
109

1110
export function authorize(props: Props): void {
12-
const { redirectURI, callback, codeVerifier } = props;
13-
if (Platform.OS === 'ios') {
14-
return Tiktok.authorize(redirectURI, callback);
15-
}
16-
17-
return Tiktok.authorize(redirectURI, callback, codeVerifier);
11+
const { redirectURI, callback } = props;
12+
return Tiktok.authorize(redirectURI, callback);
1813
}

0 commit comments

Comments
 (0)