IceCubesApp/Packages/Network/Sources/Network/Endpoint/Oauth.swift
2022-12-01 09:05:26 +01:00

37 lines
1.1 KiB
Swift

import Foundation
public enum Oauth: Endpoint {
case authorize(clientId: String)
case token(code: String, clientId: String, clientSecret: String)
public func path() -> String {
switch self {
case .authorize:
return "oauth/authorize"
case .token:
return "oauth/token"
}
}
public func queryItems() -> [URLQueryItem]? {
switch self {
case let .authorize(clientId):
return [
.init(name: "response_type", value: "code"),
.init(name: "client_id", value: clientId),
.init(name: "redirect_uri", value: "icecubesapp://"),
.init(name: "scope", value: "read write follow push")
]
case let .token(code, clientId, clientSecret):
return [
.init(name: "grant_type", value: "authorization_code"),
.init(name: "client_id", value: clientId),
.init(name: "client_secret", value: clientSecret),
.init(name: "redirect_uri", value: "icecubesapp://"),
.init(name: "code", value: code),
.init(name: "scope", value: "read write follow push")
]
}
}
}