我正在使用OAuthSwift对用户进行身份验证,但我已将用户的凭据存储在Cookie中,我需要在尝试授权之前将cookie设置为OAuthSwift实例的标头。
我知道你可以更改OAuthSwiftCredential.authorizationHeader
但是添加我自己的标题集呢?这甚至可能吗?
oauth = OAuth2Swift(consumerKey: ""...)
// Change oauth headers here>
oauth.authorize(withCallbackURL: ""...)
答案 0 :(得分:2)
/ 1.构建授权标头字符串
let auth = OAuthSwiftClient.authorizationHeaderForMethod(method.rawValue,
url: URLWithPath,
parameters: parameters!,
credential: Semantics3Router.oauthClient.credential)
// 2.发出网址请求
let URLRequest = OAuthRequestBuilder.makeRequest(URLWithPath,
method: method.rawValue,
headers: [ "Authorization" : auth ],
parameters: parameters!,
dataEncoding: dataEncoding)
答案 1 :(得分:0)
结果标头实际上内置在authorize
函数中作为可选项。直到我查看源代码时才发现它。
open func authorize(withCallbackURL callbackURL: URL, scope: String,
state: String, parameters: Parameters = [:], headers:
OAuthSwift.Headers? = nil, success: @escaping TokenSuccessHandler,
failure: FailureHandler?) -> OAuthSwiftRequestHandle?
Xcode用于显示自动填充选项的选项,我想知道为什么它不再这样做了?