From f50c219f95e3fc10df7a5cecdb26312cd4fd4173 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 3 Apr 2023 22:43:01 -0400 Subject: [PATCH] Send scopes in /oauth/token request Closes #360 --- Packages/Pachyderm/Sources/Pachyderm/Client.swift | 5 +++-- Tusker/API/MastodonController.swift | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Client.swift b/Packages/Pachyderm/Sources/Pachyderm/Client.swift index 02bd0955..f8e64c6a 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Client.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Client.swift @@ -139,13 +139,14 @@ public class Client { } } - public func getAccessToken(authorizationCode: String, redirectURI: String, completion: @escaping Callback) { + public func getAccessToken(authorizationCode: String, redirectURI: String, scopes: [Scope], completion: @escaping Callback) { let request = Request(method: .post, path: "/oauth/token", body: ParametersBody([ "client_id" => clientID, "client_secret" => clientSecret, "grant_type" => "authorization_code", "code" => authorizationCode, - "redirect_uri" => redirectURI + "redirect_uri" => redirectURI, + "scope" => scopes.scopeString, ])) run(request) { result in defer { completion(result) } diff --git a/Tusker/API/MastodonController.swift b/Tusker/API/MastodonController.swift index a2b8e60a..7d496323 100644 --- a/Tusker/API/MastodonController.swift +++ b/Tusker/API/MastodonController.swift @@ -10,6 +10,8 @@ import Foundation import Pachyderm import Combine +private let oauthScopes = [Scope.read, .write, .follow] + class MastodonController: ObservableObject { static private(set) var all = [LocalData.UserAccountInfo: MastodonController]() @@ -128,7 +130,7 @@ class MastodonController: ObservableObject { return (clientID, clientSecret) } else { let app: RegisteredApplication = try await withCheckedThrowingContinuation({ continuation in - client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: [.read, .write, .follow]) { response in + client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: oauthScopes) { response in switch response { case .failure(let error): continuation.resume(throwing: error) @@ -146,7 +148,7 @@ class MastodonController: ObservableObject { /// - Returns: The access token func authorize(authorizationCode: String) async throws -> String { return try await withCheckedThrowingContinuation({ continuation in - client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth") { response in + client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth", scopes: oauthScopes) { response in switch response { case .failure(let error): continuation.resume(throwing: error)