Swift
Swift
Generate OAuth 1.0 Signature
Demonstrates how to generate an OAuth 1.0 signature.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
success = false
let oauth = CkoOAuth1()!
// Set input parameters:
oauth.oauthVersion = "1.0"
oauth.oauthMethod = "GET"
oauth.oauthUrl = "http://echo.lab.madgex.com/echo.ashx"
oauth.consumerKey = "key"
oauth.consumerSecret = "secret"
oauth.token = "accesskey"
oauth.tokenSecret = "accesssecret"
oauth.nonce = "01020304050607080102030405060708"
oauth.timestamp = "1441659763"
// Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
oauth.signatureMethod = "HMAC-SHA256"
success = oauth.generate()
if success != true {
print("\(oauth.lastErrorText!)")
return
}
// Examine the various outputs:
print("\(oauth.queryString!)")
print("\(oauth.baseString!)")
print("\(oauth.hmacKey!)")
print("\(oauth.signature!)")
print("\(oauth.encodedSignature!)")
print("\(oauth.authorizationHeader!)")
print("\(oauth.generatedUrl!)")
}