Post JSON instead of URL queries for oauth flow

This commit is contained in:
Thomas Ricouard 2023-03-12 12:23:44 +01:00
parent 705e5514dc
commit e52712383f

View file

@ -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
}
}
}