From e52712383f5992e85b02a972e6bf406b1208c803 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 12 Mar 2023 12:23:44 +0100 Subject: [PATCH] Post JSON instead of URL queries for oauth flow --- .../Sources/Network/Endpoint/Oauth.swift | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) 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 } } }