From c5226f63744088a947dfeff1e019d4be2c3e5c95 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 6 Apr 2024 11:04:03 -0400 Subject: [PATCH] Add push scope --- Packages/Pachyderm/Sources/Pachyderm/Model/Scope.swift | 1 + Tusker/API/MastodonController.swift | 7 ++++--- Tusker/Screens/Onboarding/OnboardingViewController.swift | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Model/Scope.swift b/Packages/Pachyderm/Sources/Pachyderm/Model/Scope.swift index 75a04b77..94617f72 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Model/Scope.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Model/Scope.swift @@ -12,6 +12,7 @@ public enum Scope: String, Sendable { case read case write case follow + case push } extension Array where Element == Scope { diff --git a/Tusker/API/MastodonController.swift b/Tusker/API/MastodonController.swift index a5654569..d59bb9aa 100644 --- a/Tusker/API/MastodonController.swift +++ b/Tusker/API/MastodonController.swift @@ -17,10 +17,11 @@ import Sentry import ComposeUI import OSLog -private let oauthScopes = [Scope.read, .write, .follow] private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MastodonController") final class MastodonController: ObservableObject, Sendable { + + static let oauthScopes = [Scope.read, .write, .follow, .push] @MainActor static private(set) var all = [UserAccountInfo: MastodonController]() @@ -178,7 +179,7 @@ final class MastodonController: ObservableObject, Sendable { return (clientID, clientSecret) } else { let app: RegisteredApplication = try await withCheckedThrowingContinuation({ continuation in - client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: oauthScopes) { response in + client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: MastodonController.oauthScopes) { response in switch response { case .failure(let error): continuation.resume(throwing: error) @@ -196,7 +197,7 @@ final class MastodonController: ObservableObject, Sendable { /// - Returns: The access token func authorize(authorizationCode: String) async throws -> String { return try await withCheckedThrowingContinuation({ continuation in - client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth", scopes: oauthScopes) { response in + client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth", scopes: MastodonController.oauthScopes) { response in switch response { case .failure(let error): continuation.resume(throwing: error) diff --git a/Tusker/Screens/Onboarding/OnboardingViewController.swift b/Tusker/Screens/Onboarding/OnboardingViewController.swift index cbc9de99..0f287273 100644 --- a/Tusker/Screens/Onboarding/OnboardingViewController.swift +++ b/Tusker/Screens/Onboarding/OnboardingViewController.swift @@ -182,7 +182,7 @@ class OnboardingViewController: UINavigationController { components.queryItems = [ URLQueryItem(name: "client_id", value: clientID), URLQueryItem(name: "response_type", value: "code"), - URLQueryItem(name: "scope", value: "read write follow"), + URLQueryItem(name: "scope", value: MastodonController.oauthScopes.map(\.rawValue).joined(separator: " ")), URLQueryItem(name: "redirect_uri", value: "tusker://oauth") ] let authorizeURL = components.url!