অ্যান্ড্রয়েড অ্যাপের মধ্যে ডিজিটাল শংসাপত্র যাচাইকরণ ব্যবহারকারীর পরিচয় (যেমন একটি সরকারি পরিচয়পত্র), সেই ব্যবহারকারীর বৈশিষ্ট্য (যেমন একটি ড্রাইভিং লাইসেন্স, একাডেমিক ডিগ্রি, বা বয়স বা ঠিকানার মতো বৈশিষ্ট্য) প্রমাণীকরণ এবং অনুমোদন করতে ব্যবহার করা যেতে পারে, অথবা অন্যান্য পরিস্থিতিতে যেখানে একটি সত্তার সত্যতা নিশ্চিত করার জন্য একটি শংসাপত্র জারি এবং যাচাই করার প্রয়োজন হয়।
ডিজিটাল ক্রেডেনশিয়াল হল একটি পাবলিক W3C স্ট্যান্ডার্ড যা ডিজিটাল ওয়ালেট থেকে ব্যবহারকারীর যাচাইযোগ্য ডিজিটাল ক্রেডেনশিয়ালগুলি কীভাবে অ্যাক্সেস করতে হয় তা নির্দিষ্ট করে এবং W3C ক্রেডেনশিয়াল ম্যানেজমেন্ট API সহ ওয়েব ব্যবহারের ক্ষেত্রে এটি প্রয়োগ করা হয়। অ্যান্ড্রয়েডে, ক্রেডেনশিয়াল ম্যানেজারের DigitalCredential API ডিজিটাল ক্রেডেনশিয়াল যাচাই করার জন্য ব্যবহৃত হয়।
অ্যান্ড্রয়েড সংস্করণের সামঞ্জস্য
ভেরিফায়ার এপিআই অ্যান্ড্রয়েড ৯ (এপিআই লেভেল ২৮) এবং তার উচ্চতর সংস্করণে সমর্থিত।
বাস্তবায়ন
আপনার অ্যান্ড্রয়েড প্রজেক্টে ডিজিটাল শংসাপত্র যাচাই করতে, নিম্নলিখিতগুলি করুন:
- আপনার অ্যাপের বিল্ড স্ক্রিপ্টে নির্ভরতা যোগ করুন এবং একটি
CredentialManagerক্লাস শুরু করুন। - একটি ডিজিটাল ক্রেডেনশিয়াল রিকোয়েস্ট তৈরি করুন এবং এটি ব্যবহার করে একটি
DigitalCredentialOptionশুরু করুন, তারপরেGetCredentialRequestতৈরি করুন। - একটি সফল
GetCredentialResponseপেতে অথবা যেকোনো ব্যতিক্রম মোকাবেলা করতে নির্মিত অনুরোধের সাথেgetCredentialপ্রবাহ চালু করুন। সফল পুনরুদ্ধারের পরে, প্রতিক্রিয়াটি যাচাই করুন।
নির্ভরতা যোগ করুন এবং আরম্ভ করুন
আপনার গ্রেডল বিল্ড স্ক্রিপ্টে নিম্নলিখিত নির্ভরতা যোগ করুন:
dependencies {
implementation("androidx.credentials:credentials:1.6.0-beta01")
implementation("androidx.credentials:credentials-play-services-auth:1.6.0-beta01")
}
এরপর, CredentialManager ক্লাসের একটি উদাহরণ শুরু করুন।
val credentialManager = CredentialManager.create(context)
একটি ডিজিটাল শংসাপত্রের অনুরোধ তৈরি করুন
একটি ডিজিটাল শংসাপত্রের অনুরোধ তৈরি করুন এবং এটি ব্যবহার করে একটি DigitalCredentialOption শুরু করুন।
// The request in the JSON format to conform with
// the JSON-ified Credential Manager - Verifier API request definition.
val requestJson = generateRequestFromServer()
val digitalCredentialOption =
GetDigitalCredentialOption(requestJson = requestJson)
// Use the option from the previous step to build the `GetCredentialRequest`.
val getCredRequest = GetCredentialRequest(
listOf(digitalCredentialOption)
)
এখানে একটি OpenId4Vp অনুরোধের একটি উদাহরণ দেওয়া হল। সম্পূর্ণ রেফারেন্স এই ওয়েবসাইটে পাওয়া যাবে।
{
"requests": [
{
"protocol": "openid4vp-v1-unsigned",
"data": {
"response_type": "vp_token",
"response_mode": "dc_api",
"nonce": "OD8eP8BYfr0zyhgq4QCVEGN3m7C1Ht_No9H5fG5KJFk",
"dcql_query": {
"credentials": [
{
"id": "cred1",
"format": "mso_mdoc",
"meta": {
"doctype_value": "org.iso.18013.5.1.mDL"
},
"claims": [
{
"path": [
"org.iso.18013.5.1",
"family_name"
]
},
{
"path": [
"org.iso.18013.5.1",
"given_name"
]
},
{
"path": [
"org.iso.18013.5.1",
"age_over_21"
]
}
]
}
]
}
}
}
]
}
শংসাপত্র পান
তৈরি অনুরোধের সাথে getCredential প্রবাহ চালু করুন। আপনি হয় একটি সফল GetCredentialResponse পাবেন, অথবা অনুরোধ ব্যর্থ হলে একটি GetCredentialException পাবেন।
getCredential প্রবাহ ব্যবহারকারীর উপলব্ধ শংসাপত্রের বিকল্পগুলি উপস্থাপন করতে এবং তাদের নির্বাচন সংগ্রহ করতে অ্যান্ড্রয়েড সিস্টেম ডায়ালগগুলিকে ট্রিগার করে। এরপর, নির্বাচিত শংসাপত্রের বিকল্পটি ধারণকারী ওয়ালেট অ্যাপটি সম্মতি সংগ্রহ করতে এবং একটি ডিজিটাল শংসাপত্রের প্রতিক্রিয়া তৈরি করার জন্য প্রয়োজনীয় ক্রিয়া সম্পাদন করতে UI প্রদর্শন করবে।
coroutineScope.launch {
try {
val result = credentialManager.getCredential(
context = activityContext,
request = getCredRequest
)
verifyResult(result)
} catch (e : GetCredentialException) {
handleFailure(e)
}
}
// Handle the successfully returned credential.
fun verifyResult(result: GetCredentialResponse) {
val credential = result.credential
when (credential) {
is DigitalCredential -> {
val responseJson = credential.credentialJson
validateResponseOnServer(responseJson)
}
else -> {
// Catch any unrecognized credential type here.
Log.e(TAG, "Unexpected type of credential ${credential.type}")
}
}
}
// Handle failure.
fun handleFailure(e: GetCredentialException) {
when (e) {
is GetCredentialCancellationException -> {
// The user intentionally canceled the operation and chose not
// to share the credential.
}
is GetCredentialInterruptedException -> {
// Retry-able error. Consider retrying the call.
}
is NoCredentialException -> {
// No credential was available.
}
is CreateCredentialUnknownException -> {
// An unknown, usually unexpected, error has occurred. Check the
// message error for any additional debugging information.
}
is CreateCredentialCustomException -> {
// You have encountered a custom error thrown by the wallet.
// If you made the API call with a request object that's a
// subclass of CreateCustomCredentialRequest using a 3rd-party SDK,
// then you should check for any custom exception type constants
// within that SDK to match with e.type. Otherwise, drop or log the
// exception.
}
else -> Log.w(TAG, "Unexpected exception type ${e::class.java}")
}
}