mw99 / ohhauth Goto Github PK
View Code? Open in Web Editor NEWPure Swift implementation of the OAuth 1.0 protocol as an easy to use extension for the URLRequest type. (RFC-5849)
License: Apache License 2.0
Pure Swift implementation of the OAuth 1.0 protocol as an easy to use extension for the URLRequest type. (RFC-5849)
License: Apache License 2.0
I am attempting to use OhhAuth to calculate signatures with the Vapor server-side library. It's working pretty well, for example here where I'm doing a simple username search:
let path = URL(string:"https://api.twitter.com/1.1/users/search.json"),
var headers = HTTPHeaders()
var signature = OhhAuth.calculateSignature(
url: path,
method: "GET",
parameter: ["q" : keywords],
consumerCredentials: self.consumerCredentials,
userCredentials: self.userCredentials
)
headers.replaceOrAdd(name: .authorization, value: signature)
_ = try container.client().get("\(path)?q=\(escapedKeywords)", headers: headers).map { response -> Void in
// hooray
The process for getting a request_token, as far as I can tell, has two differences: userCredentials is nil (we're trying to get them), the parameter is a percent-escaped callback, and the signature has an oauth_callback parameter in there. (and it's POST instead of GET, nabd)
I've tried many variations on this request and always get "unauthorized" from Twitter. Am I overlooking something stupid?
var signature = OhhAuth.calculateSignature(
url: path,
method: "POST",
parameter: ["oauth_callback": "http%3A%2F%2Flocalhost%3A3000%2Fcallback%2Ftwitter"],
consumerCredentials: self.consumerCredentials,
userCredentials: nil
)
signature = signature + ",oauth_callback=\"http%3A%2F%2Flocalhost%3A3000%2Fcallback%2Ftwitter\""
Added support for sending the oauth parameters in the form-enconded body instead of just the 'authorization' header.
.diff file and changed OhhAuth.swift file attached in case you want to update the project:
form-encoded oauth parameters change.zip
Hello @mw99.
Since the update to Swift 5 some methods provided by OhhAuth API are not available anymore, because they are defined as internal.
let authenticationHeader = OhhAuth.calculateSignature(
url: url,
method: "POST",
parameter: queryParams,
consumerCredentials: credentials.consumer,
userCredentials: credentials.user
)
Cannot access calculateSignature(url: URL, method: String, parameter: [String: String], consumerCredentials: Credentials, userCredentials: Credentials?) -> String: It is internal in OhhAuth
I believe this must be a mistake. See this.
Hello,
When converting request tokens to access tokens, the api returns the error:
Auth Verification Failed: Verification of signature failed (signature base string was "GET&https%3A%2F%2Fapi.schoology.com%2Fv1%2Foauth%2Frequest_token&oauth_consumer_key%3D7c270332678c7a6b89071cd10710e9a005b90a3e0%26oauth_nonce%3D92ED8369-77FD-4E12-9166-B8B465FC0F5E%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1536906489%26oauth_token%3D98bb7e85be4900e7a0586baf5d68469105b9b54f4%26oauth_verifier%3Duivwguidsvgosdiuvgo%26oauth_version%3D1.0").
Could you look into the signature generating method when there are tokens present?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.