metatext-app-ios-iphone-ipad/MastodonAPI/Sources/MastodonAPI/Endpoints/AccessTokenEndpoint.swift

47 lines
1.1 KiB
Swift
Raw Normal View History

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
2020-08-31 03:40:58 +02:00
import HTTP
import Mastodon
2020-08-31 01:33:11 +02:00
public enum AccessTokenEndpoint {
case oauthToken(
clientID: String,
clientSecret: String,
code: String,
grantType: String,
scopes: String,
redirectURI: String
)
}
2020-08-31 01:59:49 +02:00
extension AccessTokenEndpoint: Endpoint {
2020-08-31 01:33:11 +02:00
public typealias ResultType = AccessToken
2020-08-31 01:33:11 +02:00
public var context: [String] { [] }
2020-08-31 01:33:11 +02:00
public var pathComponentsInContext: [String] {
["oauth", "token"]
}
2020-08-31 01:33:11 +02:00
public var method: HTTPMethod {
switch self {
case .oauthToken: return .post
}
}
2020-08-31 01:33:11 +02:00
public var parameters: [String: Any]? {
switch self {
case let .oauthToken(clientID, clientSecret, code, grantType, scopes, redirectURI):
return [
"client_id": clientID,
"client_secret": clientSecret,
"code": code,
"grant_type": grantType,
"scope": scopes,
"redirect_uri": redirectURI
]
}
}
}