parent
5471d810c8
commit
f50c219f95
|
@ -139,13 +139,14 @@ public class Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getAccessToken(authorizationCode: String, redirectURI: String, completion: @escaping Callback<LoginSettings>) {
|
public func getAccessToken(authorizationCode: String, redirectURI: String, scopes: [Scope], completion: @escaping Callback<LoginSettings>) {
|
||||||
let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: ParametersBody([
|
let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: ParametersBody([
|
||||||
"client_id" => clientID,
|
"client_id" => clientID,
|
||||||
"client_secret" => clientSecret,
|
"client_secret" => clientSecret,
|
||||||
"grant_type" => "authorization_code",
|
"grant_type" => "authorization_code",
|
||||||
"code" => authorizationCode,
|
"code" => authorizationCode,
|
||||||
"redirect_uri" => redirectURI
|
"redirect_uri" => redirectURI,
|
||||||
|
"scope" => scopes.scopeString,
|
||||||
]))
|
]))
|
||||||
run(request) { result in
|
run(request) { result in
|
||||||
defer { completion(result) }
|
defer { completion(result) }
|
||||||
|
|
|
@ -10,6 +10,8 @@ import Foundation
|
||||||
import Pachyderm
|
import Pachyderm
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
|
private let oauthScopes = [Scope.read, .write, .follow]
|
||||||
|
|
||||||
class MastodonController: ObservableObject {
|
class MastodonController: ObservableObject {
|
||||||
|
|
||||||
static private(set) var all = [LocalData.UserAccountInfo: MastodonController]()
|
static private(set) var all = [LocalData.UserAccountInfo: MastodonController]()
|
||||||
|
@ -128,7 +130,7 @@ class MastodonController: ObservableObject {
|
||||||
return (clientID, clientSecret)
|
return (clientID, clientSecret)
|
||||||
} else {
|
} else {
|
||||||
let app: RegisteredApplication = try await withCheckedThrowingContinuation({ continuation in
|
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 {
|
switch response {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
continuation.resume(throwing: error)
|
continuation.resume(throwing: error)
|
||||||
|
@ -146,7 +148,7 @@ class MastodonController: ObservableObject {
|
||||||
/// - Returns: The access token
|
/// - Returns: The access token
|
||||||
func authorize(authorizationCode: String) async throws -> String {
|
func authorize(authorizationCode: String) async throws -> String {
|
||||||
return try await withCheckedThrowingContinuation({ continuation in
|
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 {
|
switch response {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
continuation.resume(throwing: error)
|
continuation.resume(throwing: error)
|
||||||
|
|
Loading…
Reference in New Issue