diff --git a/example/Gemfile.lock b/example/Gemfile.lock new file mode 100644 index 0000000..13e563b --- /dev/null +++ b/example/Gemfile.lock @@ -0,0 +1,117 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (3.0.7) + base64 + nkf + rexml + activesupport (7.2.2) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) + atomos (0.1.3) + base64 (0.2.0) + benchmark (0.4.0) + bigdecimal (3.1.8) + claide (1.1.0) + cocoapods (1.15.2) + addressable (~> 2.8) + claide (>= 1.0.2, < 2.0) + cocoapods-core (= 1.15.2) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 2.1, < 3.0) + cocoapods-plugins (>= 1.0.0, < 2.0) + cocoapods-search (>= 1.0.0, < 2.0) + cocoapods-trunk (>= 1.6.0, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored2 (~> 3.1) + escape (~> 0.0.4) + fourflusher (>= 2.3.0, < 3.0) + gh_inspector (~> 1.0) + molinillo (~> 0.8.0) + nap (~> 1.0) + ruby-macho (>= 2.3.0, < 3.0) + xcodeproj (>= 1.23.0, < 2.0) + cocoapods-core (1.15.2) + activesupport (>= 5.0, < 8) + addressable (~> 2.8) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) + fuzzy_match (~> 2.0.4) + nap (~> 1.0) + netrc (~> 0.11) + public_suffix (~> 4.0) + typhoeus (~> 1.0) + cocoapods-deintegrate (1.0.5) + cocoapods-downloader (2.1) + cocoapods-plugins (1.0.0) + nap + cocoapods-search (1.0.1) + cocoapods-trunk (1.6.0) + nap (>= 0.8, < 2.0) + netrc (~> 0.11) + cocoapods-try (1.2.0) + colored2 (3.1.2) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + drb (2.2.1) + escape (0.0.4) + ethon (0.16.0) + ffi (>= 1.15.0) + ffi (1.17.0) + fourflusher (2.3.1) + fuzzy_match (2.0.4) + gh_inspector (1.1.3) + httpclient (2.8.3) + i18n (1.14.6) + concurrent-ruby (~> 1.0) + json (2.8.2) + logger (1.6.1) + minitest (5.25.1) + molinillo (0.8.0) + nanaimo (0.3.0) + nap (1.1.0) + netrc (0.11.0) + nkf (0.2.0) + public_suffix (4.0.7) + rexml (3.3.9) + ruby-macho (2.5.1) + securerandom (0.3.2) + typhoeus (1.4.1) + ethon (>= 0.9.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + xcodeproj (1.25.1) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.3.0) + rexml (>= 3.3.6, < 4.0) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (>= 6.1.7.5, != 7.1.0) + cocoapods (>= 1.13, != 1.15.1, != 1.15.0) + xcodeproj (< 1.26.0) + +RUBY VERSION + ruby 3.1.6p260 + +BUNDLED WITH + 2.3.27 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 12b64f9..c477124 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -84,6 +84,9 @@ android { targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "1.0" + manifestPlaceholders = [ + appAuthRedirectScheme: 'de.contentpass.demo' + ] } signingConfigs { debug { diff --git a/example/ios/ContentpassExample/AppDelegate.h b/example/ios/ContentpassExample/AppDelegate.h index 5d28082..96b4886 100644 --- a/example/ios/ContentpassExample/AppDelegate.h +++ b/example/ios/ContentpassExample/AppDelegate.h @@ -1,6 +1,10 @@ #import #import +#import +#import "RNAppAuthAuthorizationFlowManager.h" -@interface AppDelegate : RCTAppDelegate +@interface AppDelegate : RCTAppDelegate + +@property(nonatomic, weak) id authorizationFlowManagerDelegate; @end diff --git a/example/ios/ContentpassExample/AppDelegate.mm b/example/ios/ContentpassExample/AppDelegate.mm index beaa7ec..6e8533a 100644 --- a/example/ios/ContentpassExample/AppDelegate.mm +++ b/example/ios/ContentpassExample/AppDelegate.mm @@ -14,6 +14,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( return [super application:application didFinishLaunchingWithOptions:launchOptions]; } +- (BOOL) application: (UIApplication *)application + openURL: (NSURL *)url + options: (NSDictionary *) options +{ + if ([self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url]) { + return YES; + } + return [RCTLinkingManager application:application openURL:url options:options]; +} + - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { return [self bundleURL]; diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 8f01fba..96de977 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,4 +1,10 @@ PODS: + - AppAuth (1.7.5): + - AppAuth/Core (= 1.7.5) + - AppAuth/ExternalUserAgent (= 1.7.5) + - AppAuth/Core (1.7.5) + - AppAuth/ExternalUserAgent (1.7.5): + - AppAuth/Core - boost (1.84.0) - DoubleConversion (1.1.6) - FBLazyVector (0.76.2) @@ -1242,6 +1248,9 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga + - react-native-app-auth (8.0.0): + - AppAuth (>= 1.7.3) + - React-Core - react-native-contentpass (0.1.0): - DoubleConversion - glog @@ -1263,6 +1272,8 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga + - react-native-encrypted-storage (4.0.3): + - React-Core - React-nativeconfig (0.76.2) - React-NativeModulesApple (0.76.2): - glog @@ -1571,7 +1582,9 @@ DEPENDENCIES: - React-logger (from `../node_modules/react-native/ReactCommon/logger`) - React-Mapbuffer (from `../node_modules/react-native/ReactCommon`) - React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`) + - react-native-app-auth (from `../node_modules/react-native-app-auth`) - react-native-contentpass (from `../..`) + - react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`) - React-nativeconfig (from `../node_modules/react-native/ReactCommon`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) @@ -1603,6 +1616,7 @@ DEPENDENCIES: SPEC REPOS: trunk: + - AppAuth - SocketRocket EXTERNAL SOURCES: @@ -1677,8 +1691,12 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" React-microtasksnativemodule: :path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks" + react-native-app-auth: + :path: "../node_modules/react-native-app-auth" react-native-contentpass: :path: "../.." + react-native-encrypted-storage: + :path: "../node_modules/react-native-encrypted-storage" React-nativeconfig: :path: "../node_modules/react-native/ReactCommon" React-NativeModulesApple: @@ -1737,6 +1755,7 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/yoga" SPEC CHECKSUMS: + AppAuth: 501c04eda8a8d11f179dbe8637b7a91bb7e5d2fa boost: 1dca942403ed9342f98334bf4c3621f011aa7946 DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385 FBLazyVector: bc70dcb22ad30ce734a7cce7210791dc737e230f @@ -1772,7 +1791,9 @@ SPEC CHECKSUMS: React-logger: 81d58ca6f1d93fca9a770bda6cc1c4fbfcc99c9c React-Mapbuffer: 726951e68f4bb1c2513d322f2548798b2a3d628d React-microtasksnativemodule: 7a69a9b8fded72ea3cf81923ecf75cad5558ed26 + react-native-app-auth: c4a3b4edc11100070d8d7bc48d55fb66668cead9 react-native-contentpass: 8b690145a21ae8c50a96fe6b1a9252b6800b3a7e + react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7 React-nativeconfig: 470fce6d871c02dc5eff250a362d56391b7f52d6 React-NativeModulesApple: 6297fc3136c1fd42884795c51d7207de6312b606 React-perflogger: f2c94413cfad44817c96cab33753831e73f0d0dd diff --git a/example/package.json b/example/package.json index 14e7792..e3e135d 100644 --- a/example/package.json +++ b/example/package.json @@ -11,7 +11,9 @@ }, "dependencies": { "react": "18.3.1", - "react-native": "0.76.2" + "react-native": "0.76.2", + "react-native-app-auth": "^8.0.0", + "react-native-encrypted-storage": "^4.0.3" }, "devDependencies": { "@babel/core": "^7.25.2", diff --git a/example/src/App.tsx b/example/src/App.tsx index eed8711..c55874b 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,6 +1,6 @@ -import { useState, useEffect } from 'react'; -import { StyleSheet, View, Text } from 'react-native'; -import { multiply } from 'react-native-contentpass'; +import { StyleSheet, View } from 'react-native'; +import { ContentpassSdkProvider } from './ContentpassContext'; +import ContentpassUsage from './ContentpassUsage'; const styles = StyleSheet.create({ container: { @@ -16,15 +16,11 @@ const styles = StyleSheet.create({ }); export default function App() { - const [result, setResult] = useState(); - - useEffect(() => { - setResult(multiply(3, 7)); - }, []); - return ( - - Result: {result} - + + + + + ); } diff --git a/example/src/ContentpassContext.tsx b/example/src/ContentpassContext.tsx new file mode 100644 index 0000000..ec64cb9 --- /dev/null +++ b/example/src/ContentpassContext.tsx @@ -0,0 +1,43 @@ +import React, { createContext, useContext, useEffect, useState } from 'react'; +import { Contentpass } from 'react-native-contentpass'; +import { contentpassConfig } from './contentpassConfig'; + +const contentpassSdkContext = createContext(undefined); + +export const ContentpassSdkProvider = ({ + children, +}: { + children: React.ReactNode; +}) => { + const [contentpassSdk, setContentpassSdk] = useState< + Contentpass | undefined + >(); + + useEffect(() => { + const contentpass = new Contentpass(contentpassConfig); + + setContentpassSdk(contentpass); + }, []); + + if (!contentpassSdk) { + return null; + } + + return ( + + {children} + + ); +}; + +export const useContentpassSdk = () => { + const contentpassSdk = useContext(contentpassSdkContext); + + if (!contentpassSdk) { + throw new Error( + 'useContentpassSdk must be used within a ContentpassSdkProvider' + ); + } + + return contentpassSdk; +}; diff --git a/example/src/ContentpassUsage.tsx b/example/src/ContentpassUsage.tsx new file mode 100644 index 0000000..e4e971e --- /dev/null +++ b/example/src/ContentpassUsage.tsx @@ -0,0 +1,23 @@ +import { useContentpassSdk } from './ContentpassContext'; +import { Button, Text } from 'react-native'; +import { useState } from 'react'; +import type { AuthenticateResult } from 'react-native-contentpass'; + +export default function ContentpassUsage() { + const [authResult, setAuthResult] = useState< + AuthenticateResult | undefined + >(); + const contentpassSdk = useContentpassSdk(); + + const authenticate = async () => { + const result = await contentpassSdk.authenticate(); + setAuthResult(result); + }; + + return ( + <> +