-
Notifications
You must be signed in to change notification settings - Fork 200
Add a SwiftUI LCP authentication dialog#607
Merged
mickael-menu merged 5 commits intodevelopfrom Jun 10, 2025
Merged
Conversation
Member
Added
LCP
- A brand new LCP authentication dialog for SwiftUI applications.
Using the SwiftUI LCP Authentication dialog
If your application is built using SwiftUI, you cannot use LCPAuthenticationDialog because it requires a UIKit view controller as its host. Instead, use an LCPObservableAuthentication combined with our SwiftUI LCPDialog presented as a sheet.
@main
struct MyApp: App {
private let lcpService: LCPService
private let publicationOpener: PublicationOpener
@StateObject private var lcpAuthentication: LCPObservableAuthentication
init() {
// Create an `LCPObservableAuthentication` which will be used
// to initialize the `LCPContentProtection`.
//
// With SwiftUI, it must be stored in a `@StateObject` property
// to observe the authentication requests.
let lcpAuthentication = LCPObservableAuthentication()
_lcpAuthentication = StateObject(wrappedValue: lcpAuthentication)
lcpService = LCPService(...)
publicationOpener = PublicationOpener(
...,
contentProtections: [
lcpService.contentProtection(with: lcpAuthentication)
]
)
}
var body: some Scene {
WindowGroup {
ContentView()
// You can present an `LCPDialog` when the `LCPObservableAuthentication`
// `request` property is updated.
.sheet(item: $lcpAuthentication.request) {
LCPDialog(request: $0)
}
}
}
}
}
struct MyApp: App {
private let lcpService: LCPService
private let publicationOpener: PublicationOpener
@StateObject private var lcpAuthentication: LCPObservableAuthentication
init() {
// Create an `LCPObservableAuthentication` which will be used
// to initialize the `LCPContentProtection`.
//
// With SwiftUI, it must be stored in a `@StateObject` property
// to observe the authentication requests.
let lcpAuthentication = LCPObservableAuthentication()
_lcpAuthentication = StateObject(wrappedValue: lcpAuthentication)
lcpService = LCPService(...)
publicationOpener = PublicationOpener(
...,
contentProtections: [
lcpService.contentProtection(with: lcpAuthentication)
]
)
}
var body: some Scene {
WindowGroup {
ContentView()
// You can present an `LCPDialog` when the `LCPObservableAuthentication`
// `request` property is updated.
.sheet(item: $lcpAuthentication.request) {
LCPDialog(request: $0)
}
}
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a SwiftUI-compatible LCP authentication dialog and updates related documentation and code to support the new authentication flow. Key changes include:
- New documentation instructions for insecure HTTP requests and SwiftUI authentication usage.
- Introduction of SwiftUI components: LCPObservableAuthentication and LCPDialog.
- Updated APIs and localized strings to support the new dialog.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/Guides/Readium LCP.md | Added insecure HTTP request instructions and SwiftUI authentication usage guide. |
| Sources/LCP/Toolkit/ReadiumLCPLocalizedString.swift | Introduced a helper for localized string keys. |
| Sources/LCP/Resources/en.lproj/Localizable.strings | Updated localized strings for the new dialog and removed legacy duplicates. |
| Sources/LCP/License/Model/Components/Link.swift | Changed access level to public for certain members. |
| Sources/LCP/Authentications/LCPObservableAuthentication.swift | Added a new observable authentication implementation for SwiftUI. |
| Sources/LCP/Authentications/LCPDialog.swift | Added a new SwiftUI dialog view for LCP authentication. |
| CHANGELOG.md | Documented the new SwiftUI LCP authentication dialog feature. |
Comments suppressed due to low confidence (1)
docs/Guides/Readium LCP.md:158
- Consider adding a brief note on the security implications of allowing insecure HTTP requests to help developers understand the associated risks.
### Allow insecure HTTP requests
mickael-menu
force-pushed
the
lcp-swiftui
branch
from
June 10, 2025 14:04
e7637b5 to
2451114
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.