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(app): correlation-id usage example for ios #856

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 36 additions & 2 deletions demo/app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
8C72B0BC2A05412C00DE83DF /* Resources */,
8C72B0C12A05412C00DE83DF /* Thin Binary */,
8C72B0C22A05412C00DE83DF /* [CP] Embed Pods Frameworks */,
4FE47E993FAD0B3D3531024C /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -282,14 +283,13 @@
97C146EC1CF9000F007C117D /* Resources */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
9A352BA51F772EAC20BD57D7 /* [CP] Embed Pods Frameworks */,
7306A5726C76E01F5F688731 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
dependencies = (
);
name = Runner;
packageProductDependencies = (
);
productName = Runner;
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -387,6 +387,40 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
};
4FE47E993FAD0B3D3531024C /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PkgManager/Pods-PkgManager-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PkgManager/Pods-PkgManager-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PkgManager/Pods-PkgManager-resources.sh\"\n";
showEnvVarsInLog = 0;
};
7306A5726C76E01F5F688731 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
8C72B0AC2A05412C00DE83DF /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
90 changes: 47 additions & 43 deletions demo/app/ios/Runner/OpenID4CI.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright Gen Digital Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -12,35 +12,38 @@ public class OpenID4CI {
private var crypto: ApiCryptoProtocol
private var activityLogger: ApiActivityLoggerProtocol
private var kms: LocalkmsKMS

private var correlationID: String

private var initiatedInteraction: Openid4ciIssuerInitiatedInteraction
init (requestURI: String, didResolver: ApiDIDResolverProtocol, crypto: ApiCryptoProtocol, activityLogger: ApiActivityLoggerProtocol, kms: LocalkmsKMS) throws {

init (requestURI: String, didResolver: ApiDIDResolverProtocol, crypto: ApiCryptoProtocol, activityLogger: ApiActivityLoggerProtocol, kms: LocalkmsKMS, correlationID: String) throws {
self.didResolver = didResolver
self.crypto = crypto
self.activityLogger = activityLogger
self.kms = kms

self.correlationID = correlationID

let trace = OtelNewTrace(nil)

let args = Openid4ciNewIssuerInitiatedInteractionArgs(requestURI, crypto, didResolver)

let opts = Openid4ciNewInteractionOpts()
opts!.setActivityLogger(activityLogger)
opts!.add(trace!.traceHeader())
opts!.add(ApiHeader("X-Correlation-Id", value: self.correlationID))
opts!.enableDIProofChecks(kms)


var error: NSError?
let interaction = Openid4ciNewIssuerInitiatedInteraction(args, opts, &error)
if let actualError = error {
throw actualError
}

self.initiatedInteraction = interaction!
}


func checkFlow() throws -> String {
if ((initiatedInteraction.authorizationCodeGrantTypeSupported())){
return "auth-code-flow"
Expand All @@ -50,50 +53,50 @@ public class OpenID4CI {
}
return ""
}

func createAuthorizationURL(clientID: String, redirectURI: String, oauthDiscoverableClientURI: String, scopes:ApiStringArray) throws -> String {
var error: NSError?
let opts = Openid4ciNewCreateAuthorizationURLOpts()
if (scopes.length() != 0) {
opts!.setScopes(scopes)
}

if (oauthDiscoverableClientURI != "") {
opts!.useOAuthDiscoverableClientIDScheme()
}


let authorizationLink = initiatedInteraction.createAuthorizationURL(clientID, redirectURI: redirectURI, opts: opts, error: &error)
if let actualError = error {
print("error while creating authorization link", error!.localizedDescription)
throw actualError
}

return authorizationLink
}

func pinRequired() throws -> Bool {
return try initiatedInteraction.preAuthorizedCodeGrantParams().pinRequired()
}

func issuerURI()-> String {
return initiatedInteraction.issuerURI()
}

func getCredentialOfferDisplayData() throws -> DisplayData {
let issuerMetadata = try initiatedInteraction.issuerMetadata()

return DisplayResolveCredentialOffer(
issuerMetadata,
initiatedInteraction.offeredCredentialsTypes(), ""
)!
}

func requestCredentialWithAuth(didVerificationMethod: ApiVerificationMethod, redirectURIWithParams: String) throws -> VerifiableCredential {
let credentials = try initiatedInteraction.requestCredential(withAuth: didVerificationMethod, redirectURIWithAuthCode: redirectURIWithParams, opts: nil)
return credentials.atIndex(0)!;
}

func requestCredentials(didVerificationMethod: ApiVerificationMethod, otp: String,
attestationVC: String?, attestationVM: ApiVerificationMethod?) throws -> Array<Dictionary<String, Any>> {
let opts = Openid4ciRequestCredentialWithPreAuthOpts()!.setPIN(otp)!
Expand All @@ -105,55 +108,55 @@ public class OpenID4CI {
let credentials = try initiatedInteraction.requestCredential(withPreAuth: didVerificationMethod, opts: opts)
return convertVerifiableCredentialsWithIdArray(arr:credentials);
}

func requireAcknowledgment() throws -> ObjCBool{
var ackResp: ObjCBool = false
try initiatedInteraction.requireAcknowledgment(&ackResp)
return ackResp
}

func acknowledgeSuccess() throws {
var error: NSError?
let serializedStateResp = try initiatedInteraction.acknowledgment().serialize(&error)
if let actualError = error {
print("error from acknowledge success", actualError.localizedDescription)
throw actualError
}

let acknowledgement = try Openid4ciNewAcknowledgment(serializedStateResp, &error)
if let actualError = error {
print("error from new acknowledgement", actualError.localizedDescription)
throw actualError
}


var test = [String : String] ()
test["user"] = "123456"

let data = try JSONEncoder().encode(test)
let serializedInteractionDetails = String(data: data, encoding: .utf8)!

try acknowledgement?.setInteractionDetails(serializedInteractionDetails)

try acknowledgement?.success()
}


func acknowledgeReject() throws {
return try initiatedInteraction.acknowledgment().reject()
}

public func serializeDisplayData(issuerURI: String, vcCredentials: VerifiableCredentialsArray) -> String{
let resolvedDisplayData = DisplayResolve(vcCredentials, issuerURI, nil, nil)
return resolvedDisplayData!.serialize(nil)
}

func dynamicRegistrationSupported() throws -> ObjCBool {
var dynamicRegistrationSupported: ObjCBool = false
try initiatedInteraction.dynamicClientRegistrationSupported(&dynamicRegistrationSupported)
return dynamicRegistrationSupported
}

func dynamicRegistrationEndpoint() throws -> String {
var error: NSError?
let endpoint = initiatedInteraction.dynamicClientRegistrationEndpoint(&error)
Expand All @@ -163,10 +166,10 @@ public class OpenID4CI {
}
return endpoint
}

public func checkWithTrustRegistry(evaluateIssuanceURL: String) throws -> TrustregistryEvaluationResult {
let issuanceRequest = TrustregistryIssuanceRequest()

let trustInfo = try initiatedInteraction.issuerTrustInfo()
issuanceRequest.issuerDID = trustInfo.did
issuanceRequest.issuerDomain = trustInfo.domain
Expand All @@ -183,18 +186,19 @@ public class OpenID4CI {

let config = TrustregistryRegistryConfig()
config.evaluateIssuanceURL = evaluateIssuanceURL

config.add(ApiHeader("X-Correlation-Id", value: self.correlationID))

return try TrustregistryRegistry(config)!.evaluateIssuance(issuanceRequest)
}

func getAuthorizationCodeGrantParams() throws -> Openid4ciAuthorizationCodeGrantParams {
return try initiatedInteraction.authorizationCodeGrantParams()
}

func getIssuerMetadata() throws -> Openid4ciIssuerMetadata {
return try initiatedInteraction.issuerMetadata()
}

func verifyIssuer() throws -> String {
var error: NSError?
let issuerServiceURL = initiatedInteraction.verifyIssuer(&error)
Expand All @@ -204,6 +208,6 @@ public class OpenID4CI {
}
return issuerServiceURL
}


}
Loading
Loading