From 249f08941ef2952a9f36859e7e5a086bedd1bbe3 Mon Sep 17 00:00:00 2001 From: Madison Westergaard Date: Wed, 22 Jan 2020 16:14:08 -0800 Subject: [PATCH 01/11] Updating to 1.4 iOS SDK --- ios/Podfile | 2 +- ios/README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index e3d844e..203a3d8 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -2,7 +2,7 @@ platform :ios, '12.0' use_frameworks! target 'LoginKitSample' do - pod 'SnapSDK', '> 1.3', :subspecs => ['SCSDKLoginKit'] + pod 'SnapSDK', '> 1.4', :subspecs => ['SCSDKLoginKit'] end target 'LoginKitSampleTests' do diff --git a/ios/README.md b/ios/README.md index be3de02..6f44ce0 100644 --- a/ios/README.md +++ b/ios/README.md @@ -36,9 +36,9 @@ With the *Production* `clientID`, your app can post the content from any Snapcha 1. Open Info.plist and modify the following attributes: - * `CFBundleURLTypes`/`CFBundleTypeRole` - Set it to `Editor` - * `CFBundleURLTypes`/`CFBundleURLName` - Set it to the app's `bundleID` ie. `$(PRODUCT_BUNDLE_IDENTIFIER)` - * `CFBundleURLTypes`/`CFBundleURLSchemes` - Set it to a unique string (without space) allow Snapchat to redirect to your app after + * `URL Types`/`Document Role` - Set it to `Editor` + * `URL Types`/`URL identifier` - Set it to the app's `bundleID` ie. `$(PRODUCT_BUNDLE_IDENTIFIER)` + * `URL Types`/`URL Schemes` - Set it to a unique string (without space) allow Snapchat to redirect to your app after * `SCSDKClientId` - OAuth2 client ID you receive from registering your app * `SCSDKRedirectUrl` - the URL that Snapchat will use to redirect users back to your after a successful authorization * `LSApplicationQueriesSchemes` - Always set the value to `snapchat` From 1015078ef1ac1666c4a797947e52ca1e538fb42f Mon Sep 17 00:00:00 2001 From: Madison Westergaard Date: Thu, 23 Jan 2020 12:18:14 -0800 Subject: [PATCH 02/11] updating sdk to specific version 1.4.0 --- ios/Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Podfile b/ios/Podfile index 203a3d8..19ee996 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -2,7 +2,7 @@ platform :ios, '12.0' use_frameworks! target 'LoginKitSample' do - pod 'SnapSDK', '> 1.4', :subspecs => ['SCSDKLoginKit'] + pod 'SnapSDK', '1.4.0', :subspecs => ['SCSDKLoginKit'] end target 'LoginKitSampleTests' do From 1979bdeedb99c252f650beac0f66a9774fda05cb Mon Sep 17 00:00:00 2001 From: rkhinda Date: Tue, 7 Sep 2021 23:33:23 -0700 Subject: [PATCH 03/11] pushing react --- README.md | 5 +- react-native/.buckconfig | 6 + react-native/.eslintrc.js | 4 + react-native/.flowconfig | 73 + react-native/.gitattributes | 1 + react-native/.gitignore | 74 + react-native/.prettierrc.js | 6 + react-native/.watchmanconfig | 1 + react-native/App.tsx | 372 + react-native/README.md | 320 + react-native/__tests__/App-test.js | 14 + react-native/android/app/_BUCK | 55 + react-native/android/app/build.gradle | 220 + react-native/android/app/build_defs.bzl | 19 + react-native/android/app/debug.keystore | Bin 0 -> 2257 bytes react-native/android/app/proguard-rules.pro | 10 + .../android/app/src/debug/AndroidManifest.xml | 8 + .../ReactNativeFlipper.java | 72 + .../android/app/src/main/AndroidManifest.xml | 112 + .../reactnativeloginkitdemo/MainActivity.java | 15 + .../MainApplication.java | 80 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../app/src/main/res/values/arrays.xml | 8 + .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 9 + react-native/android/build.gradle | 41 + react-native/android/gradle.properties | 28 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 58695 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + react-native/android/gradlew | 183 + react-native/android/gradlew.bat | 103 + react-native/android/settings.gradle | 3 + react-native/app.json | 4 + react-native/babel.config.js | 3 + react-native/index.js | 9 + react-native/ios/Podfile | 33 + react-native/ios/Podfile.lock | 381 + .../ReactNativeLoginKitDemo-tvOS/Info.plist | 53 + .../Info.plist | 24 + .../project.pbxproj | 983 + .../ReactNativeLoginKitDemo-tvOS.xcscheme | 88 + .../ReactNativeLoginKitDemo.xcscheme | 88 + .../contents.xcworkspacedata | 10 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../ios/ReactNativeLoginKitDemo/AppDelegate.h | 8 + .../ios/ReactNativeLoginKitDemo/AppDelegate.m | 58 + .../AppIcon.appiconset/Contents.json | 38 + .../Images.xcassets/Contents.json | 6 + .../ios/ReactNativeLoginKitDemo/Info.plist | 145 + .../LaunchScreen.storyboard | 58 + .../ios/ReactNativeLoginKitDemo/main.m | 9 + .../ReactNativeLoginKitDemoTests/Info.plist | 24 + .../ReactNativeLoginKitDemoTests.m | 65 + react-native/jest.config.js | 4 + react-native/metro.config.js | 17 + react-native/package-lock.json | 22465 ++++++++++++++++ react-native/package.json | 35 + react-native/tsconfig.json | 21 + react-native/yarn.lock | 7164 +++++ 68 files changed, 33649 insertions(+), 2 deletions(-) create mode 100644 react-native/.buckconfig create mode 100644 react-native/.eslintrc.js create mode 100644 react-native/.flowconfig create mode 100644 react-native/.gitattributes create mode 100644 react-native/.gitignore create mode 100644 react-native/.prettierrc.js create mode 100644 react-native/.watchmanconfig create mode 100644 react-native/App.tsx create mode 100644 react-native/README.md create mode 100644 react-native/__tests__/App-test.js create mode 100644 react-native/android/app/_BUCK create mode 100644 react-native/android/app/build.gradle create mode 100644 react-native/android/app/build_defs.bzl create mode 100644 react-native/android/app/debug.keystore create mode 100644 react-native/android/app/proguard-rules.pro create mode 100644 react-native/android/app/src/debug/AndroidManifest.xml create mode 100644 react-native/android/app/src/debug/java/com/reactnativeloginkitdemo/ReactNativeFlipper.java create mode 100644 react-native/android/app/src/main/AndroidManifest.xml create mode 100644 react-native/android/app/src/main/java/com/reactnativeloginkitdemo/MainActivity.java create mode 100644 react-native/android/app/src/main/java/com/reactnativeloginkitdemo/MainApplication.java create mode 100644 react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 react-native/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 react-native/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 react-native/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 react-native/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 react-native/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 react-native/android/app/src/main/res/values/arrays.xml create mode 100644 react-native/android/app/src/main/res/values/strings.xml create mode 100644 react-native/android/app/src/main/res/values/styles.xml create mode 100644 react-native/android/build.gradle create mode 100644 react-native/android/gradle.properties create mode 100644 react-native/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 react-native/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 react-native/android/gradlew create mode 100644 react-native/android/gradlew.bat create mode 100644 react-native/android/settings.gradle create mode 100644 react-native/app.json create mode 100644 react-native/babel.config.js create mode 100644 react-native/index.js create mode 100644 react-native/ios/Podfile create mode 100644 react-native/ios/Podfile.lock create mode 100644 react-native/ios/ReactNativeLoginKitDemo-tvOS/Info.plist create mode 100644 react-native/ios/ReactNativeLoginKitDemo-tvOSTests/Info.plist create mode 100644 react-native/ios/ReactNativeLoginKitDemo.xcodeproj/project.pbxproj create mode 100644 react-native/ios/ReactNativeLoginKitDemo.xcodeproj/xcshareddata/xcschemes/ReactNativeLoginKitDemo-tvOS.xcscheme create mode 100644 react-native/ios/ReactNativeLoginKitDemo.xcodeproj/xcshareddata/xcschemes/ReactNativeLoginKitDemo.xcscheme create mode 100644 react-native/ios/ReactNativeLoginKitDemo.xcworkspace/contents.xcworkspacedata create mode 100644 react-native/ios/ReactNativeLoginKitDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 react-native/ios/ReactNativeLoginKitDemo/AppDelegate.h create mode 100644 react-native/ios/ReactNativeLoginKitDemo/AppDelegate.m create mode 100644 react-native/ios/ReactNativeLoginKitDemo/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 react-native/ios/ReactNativeLoginKitDemo/Images.xcassets/Contents.json create mode 100644 react-native/ios/ReactNativeLoginKitDemo/Info.plist create mode 100644 react-native/ios/ReactNativeLoginKitDemo/LaunchScreen.storyboard create mode 100644 react-native/ios/ReactNativeLoginKitDemo/main.m create mode 100644 react-native/ios/ReactNativeLoginKitDemoTests/Info.plist create mode 100644 react-native/ios/ReactNativeLoginKitDemoTests/ReactNativeLoginKitDemoTests.m create mode 100644 react-native/jest.config.js create mode 100644 react-native/metro.config.js create mode 100644 react-native/package-lock.json create mode 100644 react-native/package.json create mode 100644 react-native/tsconfig.json create mode 100644 react-native/yarn.lock diff --git a/README.md b/README.md index be9ac1f..2d51ff2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Login Kit Sample Apps - - [Sample iOS App](ios) - - [Sample Android App](android) +- [Sample iOS App](ios) +- [Sample Android App](android) +- [Sample React Native](react-native) diff --git a/react-native/.buckconfig b/react-native/.buckconfig new file mode 100644 index 0000000..934256c --- /dev/null +++ b/react-native/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/react-native/.eslintrc.js b/react-native/.eslintrc.js new file mode 100644 index 0000000..40c6dcd --- /dev/null +++ b/react-native/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native-community', +}; diff --git a/react-native/.flowconfig b/react-native/.flowconfig new file mode 100644 index 0000000..b274ad1 --- /dev/null +++ b/react-native/.flowconfig @@ -0,0 +1,73 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore polyfills +node_modules/react-native/Libraries/polyfills/.* + +; These should not be required directly +; require from fbjs/lib instead: require('fbjs/lib/warning') +node_modules/warning/.* + +; Flow doesn't support platforms +.*/Libraries/Utilities/LoadingView.js + +[untyped] +.*/node_modules/@react-native-community/cli/.*/.* + +[include] + +[libs] +node_modules/react-native/interface.js +node_modules/react-native/flow/ + +[options] +emoji=true + +esproposal.optional_chaining=enable +esproposal.nullish_coalescing=enable + +module.file_ext=.js +module.file_ext=.json +module.file_ext=.ios.js + +munge_underscores=true + +module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' +module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[lints] +sketchy-null-number=warn +sketchy-null-mixed=warn +sketchy-number=warn +untyped-type-import=warn +nonstrict-import=warn +deprecated-type=warn +unsafe-getters-setters=warn +unnecessary-invariant=warn +signature-verification-failure=warn +deprecated-utility=error + +[strict] +deprecated-type +nonstrict-import +sketchy-null +unclear-type +unsafe-getters-setters +untyped-import +untyped-type-import + +[version] +^0.122.0 diff --git a/react-native/.gitattributes b/react-native/.gitattributes new file mode 100644 index 0000000..d42ff18 --- /dev/null +++ b/react-native/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/react-native/.gitignore b/react-native/.gitignore new file mode 100644 index 0000000..2d6e2f9 --- /dev/null +++ b/react-native/.gitignore @@ -0,0 +1,74 @@ +# OSX +.DS_Store + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# Android/IntelliJ +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore +!debug.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle + +# CocoaPods +/ios/Pods/ + +# Found Later +android/.project +android/.settings +android/app/.classpath +android/app/.project +android/app/.settings/* + \ No newline at end of file diff --git a/react-native/.prettierrc.js b/react-native/.prettierrc.js new file mode 100644 index 0000000..5c4de1a --- /dev/null +++ b/react-native/.prettierrc.js @@ -0,0 +1,6 @@ +module.exports = { + bracketSpacing: false, + jsxBracketSameLine: true, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/react-native/.watchmanconfig b/react-native/.watchmanconfig new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/react-native/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/react-native/App.tsx b/react-native/App.tsx new file mode 100644 index 0000000..d634238 --- /dev/null +++ b/react-native/App.tsx @@ -0,0 +1,372 @@ +import LoginKit, { + LoginState, + UserData, + UserDataScopes, + VerifyResponse, +} from '@snapchat/snap-kit-react-native'; +import React, {useState} from 'react'; +import { + Alert, + Button, + DeviceEventEmitter, + Dimensions, + Image, + Modal, + NativeEventEmitter, + NativeModules, + Platform, + Pressable, + SafeAreaView, + ScrollView, + StyleSheet, + Text, + TextInput, + View, +} from 'react-native'; +var {width} = Dimensions.get('window'); + +export default function App() { + const [lastLoginState, setLastLoginState] = useState(); + const [isLoggedIn, setIsLoggedIn] = useState(false); + const [refreshAccessToken, setRefreshAccessToken] = useState( + '', + ); + const [hasAccessToScope, setHasAccessToScope] = useState(false); + const [userData, setUserData] = useState(); + const [phoneNumber, setPhoneNumber] = useState(''); + const [countryCode, setCountryCode] = useState(''); + const [verifySuccess, setVerifySuccess] = useState(null); + const [verifyError, setVerifyError] = useState(null); + const [modalVisible, setModalVisible] = useState(false); + const [isVerifyOnly, setIsVerifyOnly] = useState(false); + + React.useEffect(() => { + const onLoginStateChange = (state: LoginState) => { + setLastLoginState(state); + getIsUserLoggedInStatus(); + getRefreshAccessToken(); + getHasAccessToUserDisplayName(); + fetchUserData(); + }; + + const EventEmitter = Platform.select({ + ios: new NativeEventEmitter(NativeModules.LoginKit), + android: DeviceEventEmitter, + }); + + EventEmitter?.addListener(LoginState.LOGIN_KIT_LOGIN_STARTED, () => + onLoginStateChange(LoginState.LOGIN_KIT_LOGIN_STARTED), + ); + EventEmitter?.addListener(LoginState.LOGIN_KIT_LOGIN_SUCCEEDED, () => + onLoginStateChange(LoginState.LOGIN_KIT_LOGIN_SUCCEEDED), + ); + EventEmitter?.addListener(LoginState.LOGIN_KIT_LOGIN_FAILED, () => + onLoginStateChange(LoginState.LOGIN_KIT_LOGIN_FAILED), + ); + EventEmitter?.addListener(LoginState.LOGIN_KIT_LOGOUT, () => + onLoginStateChange(LoginState.LOGIN_KIT_LOGOUT), + ); + + getIsUserLoggedInStatus(); + getRefreshAccessToken(); + getHasAccessToUserDisplayName(); + fetchUserData(); + + return () => { + DeviceEventEmitter.removeAllListeners(); + }; + }, []); + + const verifyResult = (verifyResponse: VerifyResponse) => { + const URL = `https://api.snapkit.com/v1/phoneverify/verify_result?phone_number_id=${verifyResponse.phoneId}&phone_number_verify_id=${verifyResponse.verifyId}&phone_number=${phoneNumber}®ion=${countryCode}`; + + fetch(URL, { + method: 'POST', + }) + .then((response) => response.json()) + .then((responseJSON) => { + setVerifySuccess(responseJSON.verified); + setVerifyError(null); + }); + }; + + const getRefreshAccessToken = () => { + LoginKit.refreshAccessToken() + .then((accessToken) => setRefreshAccessToken(accessToken)) + .catch((error) => setRefreshAccessToken(error)); + }; + + const getIsUserLoggedInStatus = () => { + LoginKit.isUserLoggedIn().then((isUserLoggedIn) => + setIsLoggedIn(isUserLoggedIn), + ); + }; + + const getHasAccessToUserDisplayName = () => { + LoginKit.hasAccessToScope(UserDataScopes.DISPLAY_NAME).then((hasAccess) => + setHasAccessToScope(hasAccess), + ); + }; + + const fetchUserData = () => { + const query = '{me{bitmoji{avatar},displayName}}'; + + LoginKit.fetchUserData(query, null) + .then((data) => { + setUserData(data as UserData); + }) + .catch((error) => { + setUserData(error); + }); + }; + + return ( + + + + { + Alert.alert('Modal has been closed.'); + setModalVisible(!modalVisible); + }}> + + + What's your Mobile Number? + + + setCountryCode(country)} + placeholder={'Country Code'} + style={{flex: 0.5, textAlign: 'center'}} + /> + setPhoneNumber(number)} + placeholder={'Phone Number'} + style={{flex: 0.5, textAlign: 'center'}} + /> + + + + {verifySuccess != null + ? `Phone Verified? ${verifySuccess}` + : verifyError != null && `${verifyError}`} + + + + {verifySuccess === null && ( + setModalVisible(!modalVisible)}> + Cancel + + )} + + { + if (verifySuccess != null) { + setModalVisible(false); + } else { + if (isVerifyOnly) { + LoginKit.verify(phoneNumber, countryCode) + .then(async (response) => { + await verifyResult(response); + }) + .catch((error) => { + setVerifySuccess(null); + setVerifyError(error); + }); + } else { + LoginKit.verifyAndLogin(phoneNumber, countryCode) + .then(async (response) => { + await verifyResult(response); + }) + .catch((error) => { + setVerifySuccess(null); + setVerifyError(error); + }); + } + } + }}> + OK + + + + + + + + {userData?.bitmojiAvatar ? ( + + ) : ( + No Bitmoji avatar + )} + + {userData?.displayName ?? ''} + + + + + + {`lastLoginState: `} + {`${lastLoginState}`} + + + {`isUserLoggedIn: `} + {`${isLoggedIn}`} + + + {`accessToken: `} + {`${JSON.stringify(refreshAccessToken, null, 2)}`} + + + {`hasAccessToScope - user.display_name: `} + {`${hasAccessToScope}`} + + + {`userData: `} + {`${JSON.stringify(userData, null, 2)}`} + + + + + + +