         parameters["oauth_nonce"] = nonce
         parameters["oauth_version"] = "1.0"
         
-        let signature = String.oAuthSignature(fromMethod: "POST",
-                                              url: "https://api.twitter.com/oauth/request_token",
-                                              parameters: parameters,
-                                              with: consumerSecret)!
+        guard let signature = String.oAuthSignature(fromMethod: "POST",
+                                                    url: "https://api.twitter.com/oauth/request_token",
+                                                    parameters: parameters,
+                                                    with: consumerSecret) else {
+                                                        onFailure(nil, nil)
+                                                        return
+        }
+        
         parameters["oauth_signature"] = signature
         
         var keyValues = [String]()

        let sortedParameters = keyValues.sorted(by: {$0 < $1})
        let joinedParameters = sortedParameters.joined(separator: "&")
        guard let percentEncodedUrl = url.addingPercentEncoding(withAllowedCharacters: .twitterParameterStringSet),
            let percentEncodedJoinedParameters = joinedParameters.addingPercentEncoding(withAllowedCharacters: .twitterParameterStringSet) else {
                return nil
        }
        
        
        //join method, percent-encoded url, percent-encoded parameters
        let rawString = [method, percentEncodedUrl, percentEncodedJoinedParameters].joined(separator: "&")
        
        let hmac = HMAC(using: .sha1, key: consumerSecret.addingPercentEncoding(withAllowedCharacters: .twitterParameterStringSet)! + "&")
        let encryptedKey = hmac.update(string: rawString)!
        let encodedRawBytes = encryptedKey.final()
        let encodedData = Data(bytes: encodedRawBytes)

    }
    
    //https://dev.twitter.com/oauth/overview/creating-signatures
    static func oAuthSignature(fromMethod method: String, url: String, parameters: [String:String], with consumerSecret: String, oAuthToken: String = "") -> String? {
        var keyValues = [String]()
        for (key, value) in parameters {
            keyValues.append("\(key)=\(value.addingPercentEncoding(withAllowedCharacters: .twitterParameterStringSet)!)")
