Post JSON instead of URL queries for oauth flow
This commit is contained in:
parent
705e5514dc
commit
e52712383f
|
@ -14,6 +14,24 @@ public enum Oauth: Endpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]? {
|
public func queryItems() -> [URLQueryItem]? {
|
||||||
switch self {
|
switch self {
|
||||||
case let .authorize(clientId):
|
case let .authorize(clientId):
|
||||||
|
@ -23,15 +41,8 @@ public enum Oauth: Endpoint {
|
||||||
.init(name: "redirect_uri", value: AppInfo.scheme),
|
.init(name: "redirect_uri", value: AppInfo.scheme),
|
||||||
.init(name: "scope", value: AppInfo.scopes),
|
.init(name: "scope", value: AppInfo.scopes),
|
||||||
]
|
]
|
||||||
case let .token(code, clientId, clientSecret):
|
default:
|
||||||
return [
|
return nil
|
||||||
.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),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue