Skip to content

Commit

Permalink
added deeplinking which is working fine now
Browse files Browse the repository at this point in the history
  • Loading branch information
shreya-mishra committed Aug 22, 2023
1 parent 44fcd13 commit b166cf8
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 18 deletions.
9 changes: 1 addition & 8 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-parcelize"

import com.android.build.OutputFile

Expand Down Expand Up @@ -168,13 +168,6 @@ android {
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

// applicationVariants are e.g. debug, release
Expand Down
10 changes: 9 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter android:label="@string/app_name" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.catergory.BROWSABLE" />
<data android:scheme="app" android:host="deeplink" />
</intent-filter>

</activity>
</application>
</manifest>
69 changes: 67 additions & 2 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
const githubConfig = {
clientId: '23c78f66ab7964e5ef97',
// const githubConfig = {
// redirectUrl: 'x-realdevsquad-rdsapp://oauth2/authorize',
// clientId: '23c78f66ab7964e5ef97',
// clientSecret: '65621db87076180ab274b6dbdc1a3dd95b9dd952',
// scopes: ['notifications', 'user', 'identity'],
// serviceConfiguration: {
// authorizationEndpoint: 'https://github.com/login/oauth/authorize',
// tokenEndpoint: 'https://github.com/login/oauth/access_token',
// revocationEndpoint:
// 'https://github.com/settings/connections/applications/969f022b19e148218c41'
// },
// };

import AsyncStorage from '@react-native-async-storage/async-storage';

export const clientId = '23c78f66ab7964e5ef97';
export const clientSecret = '65621db87076180ab274b6dbdc1a3dd95b9dd952';
export const redirectUri = 'x-realdevsquad-rdsapp://oauth2/authorize';
export const tokenUrl = 'https://github.com/login/oauth/access_token';

const githubConfig = async (authorizationCode) => {

// Make POST request and handle response as previously explained
console.log('response in github config', authorizationCode);

const response = await fetch(tokenUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
client_id: clientId,
client_secret: clientSecret,
code: authorizationCode,
redirect_uri: redirectUri,
}),
});
console.log('response in github config', response);

if (response.ok) {
console.log('response is the res ok?');

const data = await response.json();
const accessToken = data.access_token;

// Call a function to securely store the access token
storeAccessTokenSecurely(accessToken);
} else {
// Handle error response
console.log('error');
console.error(
'Error exchanging code for access token:',
response.status,
response.statusText,
);
}
};

const storeAccessTokenSecurely = async (accessToken) => {
console.log('access token', accessToken);
try {
// Store the access token in a secure storage
await AsyncStorage.setItem('access_token', accessToken);
console.log('Access token stored securely.');
} catch (error) {
console.error('Error storing access token:', error);
}
};
export { githubConfig };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
"react-native-floating-action": "^1.22.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-image-picker": "^4.7.1",
"react-native-keychain": "^8.1.2",
"react-native-paper": "^4.12.3",
"react-native-radio-buttons-group": "^2.2.11",
"react-native-reanimated": "^2.2.4",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.9.0",
"react-native-toast-message": "^2.1.5",
"react-native-webview": "^11.13.0"
"react-native-webview": "^13.3.1"
},
"devDependencies": {
"@babel/core": "^7.12.9",
Expand Down
5 changes: 5 additions & 0 deletions src/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ const Index = () => {
return <TabNavigation />;
};

// https://api.realdevsquad.com/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdocs.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch

//https://github.com/login?client_id=23c78f66ab7964e5ef97&return_to=%2Flogin%2Foauth%2Fauthorize%3Fclient_id%3D23c78f66ab7964e5ef97
// https://github.com/login/oauth/authorize?client_id=23c78f66ab7964e5ef97

export default Index;
18 changes: 18 additions & 0 deletions src/navigations/linking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// export const linkingConfig = {
// prefix: 'rds://',
// const state = {
// routes: [
// {
// name: 'rooms',
// state: {
// routes: [
// {
// name: 'chat',
// params: { user: 'jane' },
// },
// ],
// },
// },
// ],
// };
// }
24 changes: 18 additions & 6 deletions src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ import { urls } from '../../constants/appConstant/url';
import AuthApis from '../../constants/apiConstant/AuthApi';
import { CameraScreen } from 'react-native-camera-kit';
import CustomModal from '../../components/Modal/CustomModal';
import { githubConfig } from '../../../config/config';
import { clientId, githubConfig } from '../../../config/config';


// baseUrl = "https://github.com/login/oauth/authorize",
// responseType = "code",
// redirectUri = "http://localhost:3000/auth/github/callback",
// scope = "user:email",
// state = "",
// clientId = defaultClientId,

const githubAuthUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&response_type=code&redirect_uri=app://deeplink&scope=user:email`;
// https://api.realdevsquad.com/auth/github/callback?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdocs.github.com%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch

const githubAuthUrl =
'https://github.com/login/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=yourappname://oauth&scope=user';
const AuthScreen = () => {
// TODO: will revamp github signIn feature
const { setLoggedInUserData } = useContext(AuthContext);

Check failure on line 43 in src/screens/AuthScreen/AuthScreen.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'githubView' is assigned a value but never used

Check failure on line 43 in src/screens/AuthScreen/AuthScreen.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'setGithubView' is assigned a value but never used
Expand All @@ -39,12 +48,16 @@ const AuthScreen = () => {
const [modalVisible, setModalVisible] = useState(false);

useEffect(() => {
console.log('inside useEffect');
Linking.getInitialURL();
const handleDeepLink = async (event) => {
console.log('handleDeep link', event);
if (event.url.startsWith('x-realdevsquad-rdsapp/oauth')) {
if (event.url.startsWith('app://deeplink')) {
console.log('inside if ', event.url);
const url = new URL(event.url);
console.log('url', url);
const authorizationCode = url.searchParams.get('code');
console.log('aut code', authorizationCode);
if (authorizationCode) {
console.log('aut code', authorizationCode);
// Call a function to exchange the code for an access token
Expand All @@ -53,11 +66,10 @@ const AuthScreen = () => {
}
};
Linking.addEventListener('url', handleDeepLink);

return () => {
Linking.removeEventListener('url', handleDeepLink);
};
}, []);
});

const activateCamera = async () => {
try {
Expand Down

0 comments on commit b166cf8

Please sign in to comment.