Add push scope

This commit is contained in:
Shadowfacts 2024-04-06 11:04:03 -04:00
parent 281585cdf0
commit c5226f6374
3 changed files with 6 additions and 4 deletions

View File

@ -12,6 +12,7 @@ public enum Scope: String, Sendable {
case read
case write
case follow
case push
}
extension Array where Element == Scope {

View File

@ -17,11 +17,12 @@ 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)

View File

@ -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!