Use Safari Controller for auth

This commit is contained in:
Thomas Ricouard 2023-01-19 11:59:40 +01:00
parent abbde84c53
commit e519e9cdff
3 changed files with 26 additions and 5 deletions

View File

@ -652,7 +652,7 @@
DEVELOPMENT_TEAM = Z6P74P6T99;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = IceCubesShareExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = IceCubesShareExtension;
INFOPLIST_KEY_CFBundleDisplayName = "Ice Cubes";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
LD_RUNPATH_SEARCH_PATHS = (
@ -682,7 +682,7 @@
DEVELOPMENT_TEAM = Z6P74P6T99;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = IceCubesShareExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = IceCubesShareExtension;
INFOPLIST_KEY_CFBundleDisplayName = "Ice Cubes";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
LD_RUNPATH_SEARCH_PATHS = (

View File

@ -7,6 +7,7 @@ import Network
import NukeUI
import Shimmer
import SwiftUI
import SafariServices
struct AddAccountView: View {
@Environment(\.dismiss) private var dismiss
@ -24,6 +25,7 @@ struct AddAccountView: View {
@State private var signInClient: Client?
@State private var instances: [InstanceSocial] = []
@State private var instanceFetchError: String?
@State private var oauthURL: URL?
private let instanceNamePublisher = PassthroughSubject<String, Never>()
@ -100,6 +102,9 @@ struct AddAccountView: View {
await continueSignIn(url: url)
}
})
.sheet(item: $oauthURL, content: { url in
SafariView(url: url)
})
}
}
@ -176,7 +181,7 @@ struct AddAccountView: View {
do {
signInClient = .init(server: instanceName)
if let oauthURL = try await signInClient?.oauthURL() {
await UIApplication.shared.open(oauthURL)
self.oauthURL = oauthURL
} else {
isSigninIn = false
}
@ -191,6 +196,7 @@ struct AddAccountView: View {
return
}
do {
oauthURL = nil
let oauthToken = try await client.continueOauthFlow(url: url)
appAccountsManager.add(account: AppAccount(server: client.server, oauthToken: oauthToken))
Task {
@ -199,7 +205,20 @@ struct AddAccountView: View {
isSigninIn = false
dismiss()
} catch {
oauthURL = nil
isSigninIn = false
}
}
}
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
SFSafariViewController(url: url)
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
}
}

View File

@ -19,8 +19,10 @@ struct ConversationsListRow: View {
AvatarView(url: conversation.accounts.first!.avatar)
VStack(alignment: .leading, spacing: 4) {
HStack {
Text(conversation.accounts.map { $0.safeDisplayName }.joined(separator: ", "))
.font(.scaledHeadline)
EmojiTextApp(conversation.accounts.map { $0.safeDisplayName }.joined(separator: ", "),
emojis: conversation.accounts.flatMap{ $0.emojis })
.font(.scaledSubheadline)
.fontWeight(.semibold)
.foregroundColor(theme.labelColor)
.multilineTextAlignment(.leading)
Spacer()