我想用 OAuth1
构建项目,我发现这样的签名请求:
Authorization:
OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1318622958",
oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
oauth_version="1.0"
但是,我怎么能得到
oauth_signature, oauth_nonce, oauth_timestamp ?
没有 postman 怎么办?
使用库 OAuthSwiftAlamofire
无需手动创建oauth_signature、oauth_nonce和oauth_timestamp。查看示例代码
let oauthswift = self.getAuth1Object()
oauthswift.client.credential.oauthToken = kAuthToken
oauthswift.client.credential.oauthTokenSecret = kAuthTokenSecret
let sessionManager = SessionManager.default
sessionManager.adapter = OAuthSwiftRequestAdapter(oauthswift)
let api = sessionManager.request(strURL,method: .post, parameters: parameters, encoding: JSONEncoding.default,headers: ["Content-Type" :"application/json"])
这是你的 getAuth1Object()
func getAuth1Object() -> OAuth1Swift {
let oauthswift = OAuth1Swift(
consumerKey: "put your consumer key here",
consumerSecret: "put your consumer secret here",
requestTokenUrl: "",
authorizeUrl: "",
accessTokenUrl: ""
)
return oauthswift
}
关于ios - 如何生成签名方法 OAuth1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43729085/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |