보유자 앱으로 사용자 인증 정보 발급 처리

발급기관의 사용자 인증 정보를 수신하고 저장하려면 보유자 앱에서 발급 흐름을 처리해야 합니다. 발급 흐름에서 발급기관 웹사이트 또는 앱은 사용자 인증 정보를 프로비저닝하는 데 필요한 정보를 자세히 설명하는 사용자 인증 정보 제안을 보유자 앱에 보냅니다. 보유자 앱은 RegistryManager를 사용하여 처리하려는 사용자 인증 정보 유형을 인증 관리자에 등록합니다. 이렇게 하면 발급 요청 중에 사용자 인증 정보를 수신하기 위해 앱이 사용자에게 표시되고 사용자가 앱을 선택할 수 있습니다.

사용자 인증 정보가 보유자 API와 작동하는 방식에 관한 자세한 내용은 보유자 API 핵심 개념을 참고하세요.

Android 버전 호환성

보유자 API는 Android 6 (API 수준 23) 이상에서 지원됩니다.

구현

인증 관리자 보유자 API를 사용하려면 다음 종속 항목을 앱 모듈의 빌드 스크립트에 추가하세요.

Groovy

dependencies {
    // Use to implement credentials registrys

    implementation "androidx.credentials.registry:registry-digitalcredentials-mdoc:1.0.0-alpha04"
    implementation "androidx.credentials.registry:registry-digitalcredentials-openid:1.0.0-alpha04"
    implementation "androidx.credentials.registry:registry-digitalcredentials-sdjwtvc:1.0.0-alpha04"
    implementation "androidx.credentials.registry:registry-provider:1.0.0-alpha04"
    implementation "androidx.credentials.registry:registry-provider-play-services:1.0.0-alpha04"

}

Kotlin

dependencies {
    // Use to implement credentials registrys

    implementation("androidx.credentials.registry:registry-digitalcredentials-mdoc:1.0.0-alpha04")
    implementation("androidx.credentials.registry:registry-digitalcredentials-openid:1.0.0-alpha04")
    implementation("androidx.credentials.registry:registry-digitalcredentials-sdjwtvc:1.0.0-alpha04")
    implementation("androidx.credentials.registry:registry-provider:1.0.0-alpha04")
    implementation("androidx.credentials.registry:registry-provider-play-services:1.0.0-alpha04")

}

RegistryManager 만들기

RegistryManager 인스턴스를 만들고 RegisterCreationOptionsRequest 요청을 등록합니다.

val registryManager = RegistryManager.create(context)

try {
    registryManager.registerCreationOptions(object :
        RegisterCreationOptionsRequest(
            creationOptions = buildIssuanceData(),
            matcher = loadIssuanceMatcher(),
            type = DigitalCredential.TYPE_DIGITAL_CREDENTIAL,
            id = "openid4vci",
        ) {}
    )
} catch (e: Exception) {
    Log.e(TAG, "Issuance registration failed.", e)
}

일치자는 등록 중에 설정된 creationOptions와 발급기관에서 보낸 사용자 인증 정보 제안을 수신하여 인증 관리자 UI에 표시되는 항목을 결정하는 WebAssembly (Wasm) 바이너리 파일입니다. 일치자의 예는 오픈소스 예시 지갑 앱을 참고하세요.

발급 요청 처리

다음으로 지갑은 사용자가 사용자 인증 정보 생성 옵션을 선택할 때 처리해야 합니다. androidx.credentials.registry.provider.action.CREATE_CREDENTIAL 인텐트 필터를 리슨하는 활동을 정의합니다. 샘플 지갑에 표시된 대로

활동을 실행하는 인텐트에는 PendingIntentHandler.retrieveProviderCreateCredentialRequest 함수로 추출할 수 있는 생성 요청 및 호출 출처가 포함되어 있습니다. API는 생성 요청과 연결된 모든 정보가 포함된 ProviderCreateCredentialRequest를 반환합니다. 두 가지 주요 구성요소가 있습니다.

  • 요청을 한 앱입니다. getCallingAppInfo로 이를 가져올 수 있습니다.
  • 호출 앱의 요청입니다. CreateCredentialRequest를 반환하는 getCallingRequest로 이를 가져올 수 있습니다. 요청이 디지털 사용자 인증 정보에 관한 것이라면 requestJson 속성에 발급 요청 JSON이 포함된 CreateDigitalCredentialRequest의 인스턴스입니다. 다음 샘플 코드로 이를 처리할 수 있습니다.
val pendingIntentRequest =
    PendingIntentHandler.retrieveProviderCreateCredentialRequest(intent)
val request = pendingIntentRequest!!.callingRequest
if (request is CreateDigitalCredentialRequest) {
    Log.i(TAG, "Got DC creation request: ${request.requestJson}")
    processCreationRequest(request.requestJson)
}

키 증명

키 증명에 관한 다음 사항에 유의하세요.

  • 키 증명을 생성할 때 BigInteger.toByteArray()를 사용하여 키 자료를 JSON 웹 키 등으로 변환할 수 있습니다. 이 메서드는 때때로 서명 바이트를 추가하고 유효성 검사 오류를 일으킬 수 있습니다. 이러한 경우에는 키 증명을 발급기관에 보내기 전에 이러한 바이트를 삭제하세요.
  • 을 키 증명 유형으로 사용하는 것이 좋습니다.android_key_attestation

생성 응답 반환

지갑에서 사용자 인증 정보를 저장하는 데 필요한 단계를 완료하면 사용자 인증 정보 응답으로 활동을 완료합니다.

val resultData = Intent()
PendingIntentHandler.setCreateCredentialResponse(
    resultData,
    CreateDigitalCredentialResponse(response.responseJson)
)
setResult(RESULT_OK, resultData)
finish()

예외가 있는 경우 마찬가지로 사용자 인증 정보 예외를 보낼 수 있습니다.

val resultData = Intent()
PendingIntentHandler.setCreateCredentialException(
    resultData,
    CreateCredentialUnknownException() // Configure the proper exception
)
setResult(RESULT_OK, resultData)
finish()

컨텍스트에서 사용자 인증 정보 응답을 반환하는 전체 예시는 샘플 앱을 참고하세요.