mastodon-ios/Mastodon/Service/APIService/APIService+Authentication.s...

58 lines
1.4 KiB
Swift
Raw Normal View History

2021-02-02 12:31:10 +01:00
//
// APIService+Authentication.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021/2/2.
//
import Foundation
import Combine
import CoreData
import CoreDataStack
import MastodonSDK
extension APIService {
func userAccessToken(
domain: String,
clientID: String,
clientSecret: String,
redirectURI: String,
2021-02-02 12:31:10 +01:00
code: String
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Token>, Error> {
let query = Mastodon.API.OAuth.AccessTokenQuery(
clientID: clientID,
clientSecret: clientSecret,
redirectURI: redirectURI,
2021-02-02 12:31:10 +01:00
code: code,
grantType: "authorization_code"
)
return Mastodon.API.OAuth.accessToken(
session: session,
domain: domain,
query: query
)
}
2021-02-05 08:58:48 +01:00
func applicationAccessToken(
domain: String,
clientID: String,
clientSecret: String,
redirectURI: String
2021-02-05 08:58:48 +01:00
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.Token>, Error> {
let query = Mastodon.API.OAuth.AccessTokenQuery(
clientID: clientID,
clientSecret: clientSecret,
redirectURI: redirectURI,
2021-02-05 08:58:48 +01:00
code: nil,
grantType: "client_credentials"
)
return Mastodon.API.OAuth.accessToken(
session: session,
domain: domain,
query: query
)
}
2021-02-02 12:31:10 +01:00
}