diff --git a/android/app/build.gradle b/android/app/build.gradle index 00927b5b..1318943b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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 @@ -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 diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 81f06f71..c8db5025 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -19,10 +19,18 @@ android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize"> - + + + + + + + + + diff --git a/config/config.js b/config/config.js index e81041ae..9b29b41b 100644 --- a/config/config.js +++ b/config/config.js @@ -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 }; diff --git a/package.json b/package.json index 45e6af51..f7fe1a35 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Index.tsx b/src/Index.tsx index e240f9f0..18ad0f9f 100644 --- a/src/Index.tsx +++ b/src/Index.tsx @@ -17,4 +17,9 @@ const Index = () => { return ; }; +// 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; diff --git a/src/navigations/linking.ts b/src/navigations/linking.ts new file mode 100644 index 00000000..80e90c6c --- /dev/null +++ b/src/navigations/linking.ts @@ -0,0 +1,18 @@ +// export const linkingConfig = { +// prefix: 'rds://', +// const state = { +// routes: [ +// { +// name: 'rooms', +// state: { +// routes: [ +// { +// name: 'chat', +// params: { user: 'jane' }, +// }, +// ], +// }, +// }, +// ], +// }; +// } \ No newline at end of file diff --git a/src/screens/AuthScreen/AuthScreen.tsx b/src/screens/AuthScreen/AuthScreen.tsx index 68851ee4..b439dac0 100644 --- a/src/screens/AuthScreen/AuthScreen.tsx +++ b/src/screens/AuthScreen/AuthScreen.tsx @@ -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); @@ -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 @@ -53,11 +66,10 @@ const AuthScreen = () => { } }; Linking.addEventListener('url', handleDeepLink); - return () => { Linking.removeEventListener('url', handleDeepLink); }; - }, []); + }); const activateCamera = async () => { try {