forked from shadowfacts/Tusker
Add push scope
This commit is contained in:
parent
281585cdf0
commit
c5226f6374
|
@ -12,6 +12,7 @@ public enum Scope: String, Sendable {
|
||||||
case read
|
case read
|
||||||
case write
|
case write
|
||||||
case follow
|
case follow
|
||||||
|
case push
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Array where Element == Scope {
|
extension Array where Element == Scope {
|
||||||
|
|
|
@ -17,10 +17,11 @@ import Sentry
|
||||||
import ComposeUI
|
import ComposeUI
|
||||||
import OSLog
|
import OSLog
|
||||||
|
|
||||||
private let oauthScopes = [Scope.read, .write, .follow]
|
|
||||||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MastodonController")
|
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "MastodonController")
|
||||||
|
|
||||||
final class MastodonController: ObservableObject, Sendable {
|
final class MastodonController: ObservableObject, Sendable {
|
||||||
|
|
||||||
|
static let oauthScopes = [Scope.read, .write, .follow, .push]
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
static private(set) var all = [UserAccountInfo: MastodonController]()
|
static private(set) var all = [UserAccountInfo: MastodonController]()
|
||||||
|
@ -178,7 +179,7 @@ final class MastodonController: ObservableObject, Sendable {
|
||||||
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: oauthScopes) { response in
|
client.registerApp(name: "Tusker", redirectURI: "tusker://oauth", scopes: MastodonController.oauthScopes) { response in
|
||||||
switch response {
|
switch response {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
continuation.resume(throwing: error)
|
continuation.resume(throwing: error)
|
||||||
|
@ -196,7 +197,7 @@ final class MastodonController: ObservableObject, Sendable {
|
||||||
/// - 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", scopes: oauthScopes) { response in
|
client.getAccessToken(authorizationCode: authorizationCode, redirectURI: "tusker://oauth", scopes: MastodonController.oauthScopes) { response in
|
||||||
switch response {
|
switch response {
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
continuation.resume(throwing: error)
|
continuation.resume(throwing: error)
|
||||||
|
|
|
@ -182,7 +182,7 @@ class OnboardingViewController: UINavigationController {
|
||||||
components.queryItems = [
|
components.queryItems = [
|
||||||
URLQueryItem(name: "client_id", value: clientID),
|
URLQueryItem(name: "client_id", value: clientID),
|
||||||
URLQueryItem(name: "response_type", value: "code"),
|
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")
|
URLQueryItem(name: "redirect_uri", value: "tusker://oauth")
|
||||||
]
|
]
|
||||||
let authorizeURL = components.url!
|
let authorizeURL = components.url!
|
||||||
|
|
Loading…
Reference in New Issue