diff --git a/Packages/Network/Sources/Network/Endpoint/Oauth.swift b/Packages/Network/Sources/Network/Endpoint/Oauth.swift index f611f65e..4a5e4b71 100644 --- a/Packages/Network/Sources/Network/Endpoint/Oauth.swift +++ b/Packages/Network/Sources/Network/Endpoint/Oauth.swift @@ -13,6 +13,24 @@ public enum Oauth: Endpoint { return "oauth/token" } } + + public var jsonValue: Encodable? { + switch self { + case let .token(code, clientId, clientSecret): + return TokenData(clientId: clientId, clientSecret: clientSecret, code: code) + default: + return nil + } + } + + public struct TokenData: Encodable { + public let grantType = "authorization_code" + public let clientId: String + public let clientSecret: String + public let redirectUri = AppInfo.scheme + public let code: String + public let scope = AppInfo.scopes + } public func queryItems() -> [URLQueryItem]? { switch self { @@ -23,15 +41,8 @@ public enum Oauth: Endpoint { .init(name: "redirect_uri", value: AppInfo.scheme), .init(name: "scope", value: AppInfo.scopes), ] - 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: AppInfo.scheme), - .init(name: "code", value: code), - .init(name: "scope", value: AppInfo.scopes), - ] + default: + return nil } } }