Skip to content

Commit e09731b

Browse files
authored
Merge pull request #2 from contentpass/CP-2492-Add-authenticate-method
Add authenticate method
2 parents 0a9c14d + d182524 commit e09731b

17 files changed

+445
-18
lines changed

example/Gemfile.lock

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
CFPropertyList (3.0.7)
5+
base64
6+
nkf
7+
rexml
8+
activesupport (7.2.2)
9+
base64
10+
benchmark (>= 0.3)
11+
bigdecimal
12+
concurrent-ruby (~> 1.0, >= 1.3.1)
13+
connection_pool (>= 2.2.5)
14+
drb
15+
i18n (>= 1.6, < 2)
16+
logger (>= 1.4.2)
17+
minitest (>= 5.1)
18+
securerandom (>= 0.3)
19+
tzinfo (~> 2.0, >= 2.0.5)
20+
addressable (2.8.7)
21+
public_suffix (>= 2.0.2, < 7.0)
22+
algoliasearch (1.27.5)
23+
httpclient (~> 2.8, >= 2.8.3)
24+
json (>= 1.5.1)
25+
atomos (0.1.3)
26+
base64 (0.2.0)
27+
benchmark (0.4.0)
28+
bigdecimal (3.1.8)
29+
claide (1.1.0)
30+
cocoapods (1.15.2)
31+
addressable (~> 2.8)
32+
claide (>= 1.0.2, < 2.0)
33+
cocoapods-core (= 1.15.2)
34+
cocoapods-deintegrate (>= 1.0.3, < 2.0)
35+
cocoapods-downloader (>= 2.1, < 3.0)
36+
cocoapods-plugins (>= 1.0.0, < 2.0)
37+
cocoapods-search (>= 1.0.0, < 2.0)
38+
cocoapods-trunk (>= 1.6.0, < 2.0)
39+
cocoapods-try (>= 1.1.0, < 2.0)
40+
colored2 (~> 3.1)
41+
escape (~> 0.0.4)
42+
fourflusher (>= 2.3.0, < 3.0)
43+
gh_inspector (~> 1.0)
44+
molinillo (~> 0.8.0)
45+
nap (~> 1.0)
46+
ruby-macho (>= 2.3.0, < 3.0)
47+
xcodeproj (>= 1.23.0, < 2.0)
48+
cocoapods-core (1.15.2)
49+
activesupport (>= 5.0, < 8)
50+
addressable (~> 2.8)
51+
algoliasearch (~> 1.0)
52+
concurrent-ruby (~> 1.1)
53+
fuzzy_match (~> 2.0.4)
54+
nap (~> 1.0)
55+
netrc (~> 0.11)
56+
public_suffix (~> 4.0)
57+
typhoeus (~> 1.0)
58+
cocoapods-deintegrate (1.0.5)
59+
cocoapods-downloader (2.1)
60+
cocoapods-plugins (1.0.0)
61+
nap
62+
cocoapods-search (1.0.1)
63+
cocoapods-trunk (1.6.0)
64+
nap (>= 0.8, < 2.0)
65+
netrc (~> 0.11)
66+
cocoapods-try (1.2.0)
67+
colored2 (3.1.2)
68+
concurrent-ruby (1.3.4)
69+
connection_pool (2.4.1)
70+
drb (2.2.1)
71+
escape (0.0.4)
72+
ethon (0.16.0)
73+
ffi (>= 1.15.0)
74+
ffi (1.17.0)
75+
fourflusher (2.3.1)
76+
fuzzy_match (2.0.4)
77+
gh_inspector (1.1.3)
78+
httpclient (2.8.3)
79+
i18n (1.14.6)
80+
concurrent-ruby (~> 1.0)
81+
json (2.8.2)
82+
logger (1.6.1)
83+
minitest (5.25.1)
84+
molinillo (0.8.0)
85+
nanaimo (0.3.0)
86+
nap (1.1.0)
87+
netrc (0.11.0)
88+
nkf (0.2.0)
89+
public_suffix (4.0.7)
90+
rexml (3.3.9)
91+
ruby-macho (2.5.1)
92+
securerandom (0.3.2)
93+
typhoeus (1.4.1)
94+
ethon (>= 0.9.0)
95+
tzinfo (2.0.6)
96+
concurrent-ruby (~> 1.0)
97+
xcodeproj (1.25.1)
98+
CFPropertyList (>= 2.3.3, < 4.0)
99+
atomos (~> 0.1.3)
100+
claide (>= 1.0.2, < 2.0)
101+
colored2 (~> 3.1)
102+
nanaimo (~> 0.3.0)
103+
rexml (>= 3.3.6, < 4.0)
104+
105+
PLATFORMS
106+
ruby
107+
108+
DEPENDENCIES
109+
activesupport (>= 6.1.7.5, != 7.1.0)
110+
cocoapods (>= 1.13, != 1.15.1, != 1.15.0)
111+
xcodeproj (< 1.26.0)
112+
113+
RUBY VERSION
114+
ruby 3.1.6p260
115+
116+
BUNDLED WITH
117+
2.3.27

example/android/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ android {
8484
targetSdkVersion rootProject.ext.targetSdkVersion
8585
versionCode 1
8686
versionName "1.0"
87+
manifestPlaceholders = [
88+
appAuthRedirectScheme: 'de.contentpass.demo'
89+
]
8790
}
8891
signingConfigs {
8992
debug {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#import <RCTAppDelegate.h>
22
#import <UIKit/UIKit.h>
3+
#import <React/RCTLinkingManager.h>
4+
#import "RNAppAuthAuthorizationFlowManager.h"
35

4-
@interface AppDelegate : RCTAppDelegate
6+
@interface AppDelegate : RCTAppDelegate <RNAppAuthAuthorizationFlowManager>
7+
8+
@property(nonatomic, weak) id<RNAppAuthAuthorizationFlowManagerDelegate> authorizationFlowManagerDelegate;
59

610
@end

example/ios/ContentpassExample/AppDelegate.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1414
return [super application:application didFinishLaunchingWithOptions:launchOptions];
1515
}
1616

17+
- (BOOL) application: (UIApplication *)application
18+
openURL: (NSURL *)url
19+
options: (NSDictionary<UIApplicationOpenURLOptionsKey, id> *) options
20+
{
21+
if ([self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url]) {
22+
return YES;
23+
}
24+
return [RCTLinkingManager application:application openURL:url options:options];
25+
}
26+
1727
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
1828
{
1929
return [self bundleURL];

example/ios/Podfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
PODS:
2+
- AppAuth (1.7.5):
3+
- AppAuth/Core (= 1.7.5)
4+
- AppAuth/ExternalUserAgent (= 1.7.5)
5+
- AppAuth/Core (1.7.5)
6+
- AppAuth/ExternalUserAgent (1.7.5):
7+
- AppAuth/Core
28
- boost (1.84.0)
39
- DoubleConversion (1.1.6)
410
- FBLazyVector (0.76.2)
@@ -1242,6 +1248,9 @@ PODS:
12421248
- ReactCommon/turbomodule/bridging
12431249
- ReactCommon/turbomodule/core
12441250
- Yoga
1251+
- react-native-app-auth (8.0.0):
1252+
- AppAuth (>= 1.7.3)
1253+
- React-Core
12451254
- react-native-contentpass (0.1.0):
12461255
- DoubleConversion
12471256
- glog
@@ -1263,6 +1272,8 @@ PODS:
12631272
- ReactCommon/turbomodule/bridging
12641273
- ReactCommon/turbomodule/core
12651274
- Yoga
1275+
- react-native-encrypted-storage (4.0.3):
1276+
- React-Core
12661277
- React-nativeconfig (0.76.2)
12671278
- React-NativeModulesApple (0.76.2):
12681279
- glog
@@ -1571,7 +1582,9 @@ DEPENDENCIES:
15711582
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
15721583
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
15731584
- React-microtasksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/microtasks`)
1585+
- react-native-app-auth (from `../node_modules/react-native-app-auth`)
15741586
- react-native-contentpass (from `../..`)
1587+
- react-native-encrypted-storage (from `../node_modules/react-native-encrypted-storage`)
15751588
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
15761589
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
15771590
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -1603,6 +1616,7 @@ DEPENDENCIES:
16031616

16041617
SPEC REPOS:
16051618
trunk:
1619+
- AppAuth
16061620
- SocketRocket
16071621

16081622
EXTERNAL SOURCES:
@@ -1677,8 +1691,12 @@ EXTERNAL SOURCES:
16771691
:path: "../node_modules/react-native/ReactCommon"
16781692
React-microtasksnativemodule:
16791693
:path: "../node_modules/react-native/ReactCommon/react/nativemodule/microtasks"
1694+
react-native-app-auth:
1695+
:path: "../node_modules/react-native-app-auth"
16801696
react-native-contentpass:
16811697
:path: "../.."
1698+
react-native-encrypted-storage:
1699+
:path: "../node_modules/react-native-encrypted-storage"
16821700
React-nativeconfig:
16831701
:path: "../node_modules/react-native/ReactCommon"
16841702
React-NativeModulesApple:
@@ -1737,6 +1755,7 @@ EXTERNAL SOURCES:
17371755
:path: "../node_modules/react-native/ReactCommon/yoga"
17381756

17391757
SPEC CHECKSUMS:
1758+
AppAuth: 501c04eda8a8d11f179dbe8637b7a91bb7e5d2fa
17401759
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
17411760
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
17421761
FBLazyVector: bc70dcb22ad30ce734a7cce7210791dc737e230f
@@ -1772,7 +1791,9 @@ SPEC CHECKSUMS:
17721791
React-logger: 81d58ca6f1d93fca9a770bda6cc1c4fbfcc99c9c
17731792
React-Mapbuffer: 726951e68f4bb1c2513d322f2548798b2a3d628d
17741793
React-microtasksnativemodule: 7a69a9b8fded72ea3cf81923ecf75cad5558ed26
1794+
react-native-app-auth: c4a3b4edc11100070d8d7bc48d55fb66668cead9
17751795
react-native-contentpass: 8b690145a21ae8c50a96fe6b1a9252b6800b3a7e
1796+
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
17761797
React-nativeconfig: 470fce6d871c02dc5eff250a362d56391b7f52d6
17771798
React-NativeModulesApple: 6297fc3136c1fd42884795c51d7207de6312b606
17781799
React-perflogger: f2c94413cfad44817c96cab33753831e73f0d0dd

example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
},
1212
"dependencies": {
1313
"react": "18.3.1",
14-
"react-native": "0.76.2"
14+
"react-native": "0.76.2",
15+
"react-native-app-auth": "^8.0.0",
16+
"react-native-encrypted-storage": "^4.0.3"
1517
},
1618
"devDependencies": {
1719
"@babel/core": "^7.25.2",

example/src/App.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useState, useEffect } from 'react';
2-
import { StyleSheet, View, Text } from 'react-native';
3-
import { multiply } from 'react-native-contentpass';
1+
import { StyleSheet, View } from 'react-native';
2+
import { ContentpassSdkProvider } from './ContentpassContext';
3+
import ContentpassUsage from './ContentpassUsage';
44

55
const styles = StyleSheet.create({
66
container: {
@@ -16,15 +16,11 @@ const styles = StyleSheet.create({
1616
});
1717

1818
export default function App() {
19-
const [result, setResult] = useState<number | undefined>();
20-
21-
useEffect(() => {
22-
setResult(multiply(3, 7));
23-
}, []);
24-
2519
return (
26-
<View style={styles.container}>
27-
<Text>Result: {result}</Text>
28-
</View>
20+
<ContentpassSdkProvider>
21+
<View style={styles.container}>
22+
<ContentpassUsage />
23+
</View>
24+
</ContentpassSdkProvider>
2925
);
3026
}

example/src/ContentpassContext.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { createContext, useContext, useEffect, useState } from 'react';
2+
import { Contentpass } from 'react-native-contentpass';
3+
import { contentpassConfig } from './contentpassConfig';
4+
5+
const contentpassSdkContext = createContext<Contentpass | undefined>(undefined);
6+
7+
export const ContentpassSdkProvider = ({
8+
children,
9+
}: {
10+
children: React.ReactNode;
11+
}) => {
12+
const [contentpassSdk, setContentpassSdk] = useState<
13+
Contentpass | undefined
14+
>();
15+
16+
useEffect(() => {
17+
const contentpass = new Contentpass(contentpassConfig);
18+
19+
setContentpassSdk(contentpass);
20+
}, []);
21+
22+
if (!contentpassSdk) {
23+
return null;
24+
}
25+
26+
return (
27+
<contentpassSdkContext.Provider value={contentpassSdk}>
28+
{children}
29+
</contentpassSdkContext.Provider>
30+
);
31+
};
32+
33+
export const useContentpassSdk = () => {
34+
const contentpassSdk = useContext(contentpassSdkContext);
35+
36+
if (!contentpassSdk) {
37+
throw new Error(
38+
'useContentpassSdk must be used within a ContentpassSdkProvider'
39+
);
40+
}
41+
42+
return contentpassSdk;
43+
};

example/src/ContentpassUsage.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useContentpassSdk } from './ContentpassContext';
2+
import { Button, Text } from 'react-native';
3+
import { useState } from 'react';
4+
import type { AuthenticateResult } from 'react-native-contentpass';
5+
6+
export default function ContentpassUsage() {
7+
const [authResult, setAuthResult] = useState<
8+
AuthenticateResult | undefined
9+
>();
10+
const contentpassSdk = useContentpassSdk();
11+
12+
const authenticate = async () => {
13+
const result = await contentpassSdk.authenticate();
14+
setAuthResult(result);
15+
};
16+
17+
return (
18+
<>
19+
<Button title={'Authenticate'} onPress={authenticate} />
20+
<Text>Result: {JSON.stringify(authResult)}</Text>
21+
</>
22+
);
23+
}

example/src/contentpassConfig.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Config } from 'react-native-contentpass';
2+
3+
export const contentpassConfig: Config = {
4+
propertyId: 'cc3fc4ad-cbe5-4d09-bf85-a49796603b19',
5+
redirectUrl: 'de.contentpass.demo://oauth',
6+
};

0 commit comments

Comments
 (0)