Skip to content

Commit

Permalink
Merge pull request #31 from moratori/interpret-response-code-after-vp…
Browse files Browse the repository at this point in the history
…-rdt435

Open the `redirect_uri` obtained after VP in an external app.
  • Loading branch information
sadamu authored Oct 11, 2024
2 parents ce194db + 82bd328 commit 1261a1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 38 deletions.
13 changes: 0 additions & 13 deletions tw2023_wallet/Feature/ShareCredential/Views/RedirectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,6 @@ struct RedirectView: View {
)
}
}

func openURLInSafari(urlString: String) {
if let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
presentationMode.wrappedValue.dismiss()
}
else {
print("invalid url is specified.")
alertTitle = "URLが不正です"
alertMessage = urlString
showAlert = true
}
}
}

#Preview {
Expand Down
35 changes: 10 additions & 25 deletions tw2023_wallet/tw2023_walletApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extension String: Identifiable {
struct tw2023_walletApp: App {
@State private var credentialOffer: String? = nil
@State private var openID4VP: String? = nil
@State private var navigateToRedirectView = false

@State private var sharingRequestModel = SharingRequestModel()

Expand Down Expand Up @@ -59,36 +58,13 @@ struct tw2023_walletApp: App {
if let postResult = sharingRequestModel.postResult,
let location = postResult.location
{
navigateToRedirectView.toggle()
openURLInExternalApp(urlString: location)
}
}
) { value in
SharingRequest(args: createOpenID4VPArgs(value: value)).environment(
sharingRequestModel)
}
.fullScreenCover(
isPresented: $navigateToRedirectView,
onDismiss: {
navigateToRedirectView = false
}
) {
// let (urlString, cookies) = getRedirectParameters()
if let postResult = sharingRequestModel.postResult,
let urlString = postResult.location
{
NavigationView {
RedirectView(urlString: urlString, cookieStrings: [])
.navigationBarItems(
trailing: Button("close") {
navigateToRedirectView = false
}
)
}
}
else {
EmptyView()
}
}
}
else {
AuthenticationView(authenticationManager: self.authenticationManager).onOpenURL(
Expand All @@ -103,6 +79,15 @@ struct tw2023_walletApp: App {
}
}

private func openURLInExternalApp(urlString: String) {
if let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
else {
print("invalid url is specified.")
}
}

private func handleScenePhaseChange(_ newPhase: ScenePhase) {
switch newPhase {
case .active:
Expand Down

0 comments on commit 1261a1f

Please sign in to comment.