OGeek|极客世界-中国程序员成长平台

标题: ios - 如何生成签名方法 OAuth1 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:35
标题: ios - 如何生成签名方法 OAuth1

我想用 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 怎么办?



Best Answer-推荐答案


使用库 OAuthSwiftAlamofire

无需手动创建oauth_signatureoauth_nonceoauth_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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4