Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: DigiLocker integration to fetch Aadhaar, PAN and Driving License #217

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0ab13db
added google login and drive api wrapper dependency
piyushupadhyay19 Jun 24, 2024
3a64aa2
Updated .gitignore to exclude vs code files
piyushupadhyay19 Jun 24, 2024
67a5e64
google login functionality
piyushupadhyay19 Jun 24, 2024
2fb8f30
upload backup file to google drive
piyushupadhyay19 Jun 27, 2024
b42690c
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Jun 27, 2024
558c1f0
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Jul 1, 2024
8e1febc
improved variable names and removed signout toast
piyushupadhyay19 Jul 1, 2024
9ff7c88
feat: google drive integration with a sign-in flow and backup upload
piyushupadhyay19 Jul 3, 2024
c93c459
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Jul 3, 2024
e90a730
feat: add ios google integration (#204)
sairanjit Jul 4, 2024
32a20c1
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Jul 5, 2024
fc67c27
fix: W3C fixes (#205)
sairanjit Jul 6, 2024
1aacbd2
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Jul 9, 2024
16b8d4b
restore wallet instructions
piyushupadhyay19 Jul 10, 2024
ac07928
feat: add restore wallet instructions (#207)
piyushupadhyay19 Aug 1, 2024
313f14c
Merge branch 'dev' of https://github.com/piyushupadhyay19/adeya-walle…
piyushupadhyay19 Aug 19, 2024
69a7a51
digilocker integration for aadhaar pan and drivingLicense details
piyushupadhyay19 Sep 8, 2024
7a10f66
Merge branch 'develop' of https://github.com/piyushupadhyay19/adeya-w…
piyushupadhyay19 Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions app/api/digilocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import AsyncStorage from '@react-native-async-storage/async-storage'
import axios from 'axios'
import { Linking } from 'react-native'
import { Config } from 'react-native-config'

import { generateCodeChallenge } from '../utils/crypto'

const DIGILOCKER_CLIENT_ID = Config.DIGILOCKER_CLIENT_ID
const DIGILOCKER_CLIENT_SECRET = Config.DIGILOCKER_CLIENT_SECRET
const DIGILOCKER_REDIRECT_URI = Config.DIGILOCKER_REDIRECT_URI

export const initiateDigiLockerOAuth = async (codeVerifier: string): Promise<void | Error> => {
try {
AsyncStorage.setItem('codeVerifier', codeVerifier)
const codeChallenge = generateCodeChallenge(codeVerifier)

const authUrl = `https://api.digitallocker.gov.in/public/oauth2/1/authorize?response_type=code&client_id=${DIGILOCKER_CLIENT_ID}&redirect_uri=${DIGILOCKER_REDIRECT_URI}&state=adeya2024&code_challenge=${codeChallenge}&code_challenge_method=S256`

await Linking.openURL(authUrl)
} catch (error) {
return error instanceof Error ? error : new Error('An unknown error occurred')
}
}

export const fetchDigiLockerToken = async (
authCode: string,
codeVerifier: string,
): Promise<any | { message: string }> => {
const tokenUrl = 'https://api.digitallocker.gov.in/public/oauth2/1/token'
const clientSecret = DIGILOCKER_CLIENT_SECRET
const clientId = DIGILOCKER_CLIENT_ID
const redirectUri = DIGILOCKER_REDIRECT_URI

const params =
`grant_type=authorization_code&` +
`code=${encodeURIComponent(authCode)}&` +
`client_id=${encodeURIComponent(clientId)}&` +
`client_secret=${encodeURIComponent(clientSecret)}&` +
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
`code_verifier=${encodeURIComponent(codeVerifier)}`

try {
const response = await axios.post(tokenUrl, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
})
return response.data
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'
return { message: `Error fetching DigiLocker token: ${errorMessage}` }
}
}

export const fetchAadhaarData = async (accessToken: string): Promise<any | { message: string }> => {
const aadhaarUrl = 'https://api.digitallocker.gov.in/public/oauth2/3/xml/eaadhaar'

try {
const response = await axios.get(aadhaarUrl, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
return response.data
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'
return { message: `Error fetching Aadhaar data: ${errorMessage}` }
}
}

export const fetchIssuedDocuments = async (accessToken: string): Promise<any | { message: string }> => {
const issuedDocumentsUrl = 'https://api.digitallocker.gov.in/public/oauth2/2/files/issued'

try {
const response = await axios.get(issuedDocumentsUrl, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
return response.data
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'
return { message: `Error fetching issued documents: ${errorMessage}` }
}
}

export const fetchDocumentData = async (uri: string, accessToken: string): Promise<any | { message: string }> => {
const documentUrl = `https://api.digitallocker.gov.in/public/oauth2/1/xml/${uri}`

try {
const response = await axios.get(documentUrl, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
return response.data
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'
return { message: `Error fetching document data: ${errorMessage}` }
}
}

export const fetchDocument = async (uri: string, accessToken: string): Promise<any | { message: string }> => {
const documentUrl = `https://api.digitallocker.gov.in/public/oauth2/1/file/${uri}`

try {
const response = await axios.get(documentUrl, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
})
return response.data
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred'
return { message: `Error fetching document data: ${errorMessage}` }
}
}
5 changes: 5 additions & 0 deletions app/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ const translation = {
"OrganizationConnection": "Connection",
"RenderCertificate": "Certificate",
"GoogleDriveSignIn": "Google Drive Sign In",
"DigiLocker": "Fetch From DigiLocker"
},
"Loading": {
"TakingTooLong": "This is taking longer than usual. You can return to home or continue waiting.",
Expand Down Expand Up @@ -731,6 +732,10 @@ const translation = {
"RestoreInstructions": "Note: To restore your wallet, you can use a backup from your cloud storage or local device. Please ensure that the Google Drive app is installed on your device and you are signed in.",
"RestoreInstructionsIOS": "If you can't see Google Drive in the file picker, open the Files app --> tap on the three dots at the top --> select 'Edit' --> enable Google Drive.",
},
"DigiLocker": {
"Government": " Government IDs",
"DigiLockerInstructions": "Note: To fetch your documents from DigiLocker, you need to authenticate with your DigiLocker account.",
},
}

export default translation
6 changes: 6 additions & 0 deletions app/navigators/SettingStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useConfiguration } from '../contexts/configuration'
import { useTheme } from '../contexts/theme'
import CreateWallet from '../screens/CreateWallet'
import DataRetention from '../screens/DataRetention'
import DigiLockerScreen from '../screens/DigiLockerScreen'
import ExportWallet from '../screens/ExportWallet'
import ExportWalletConfirmation from '../screens/ExportWalletConfirmation'
import GoogleDriveSignIn from '../screens/GoogleDriveSignIn'
Expand Down Expand Up @@ -94,6 +95,11 @@ const SettingStack: React.FC = () => {
component={terms}
options={{ title: t('Screens.Terms'), headerBackTestID: testIdWithKey('Back') }}
/>
<Stack.Screen
name={Screens.DigiLockerScreen}
component={DigiLockerScreen}
options={{ title: 'Fetch From DigiLocker', headerBackTestID: testIdWithKey('Back') }}
/>
<Stack.Screen
name={Screens.Developer}
component={developer}
Expand Down
Loading