{"id":13635341,"url":"https://github.com/mw99/OhhAuth","last_synced_at":"2025-04-19T03:34:56.222Z","repository":{"id":45900998,"uuid":"90113529","full_name":"mw99/OhhAuth","owner":"mw99","description":"Pure Swift implementation of the OAuth 1.0 protocol as an easy to use extension for the URLRequest type. (RFC-5849)","archived":false,"fork":false,"pushed_at":"2022-08-27T15:15:33.000Z","size":16,"stargazers_count":36,"open_issues_count":3,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-02T03:33:45.529Z","etag":null,"topics":["extension","ios","oauth","swift","urlrequest"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mw99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-03T05:58:53.000Z","updated_at":"2024-07-28T07:04:08.000Z","dependencies_parsed_at":"2022-08-06T09:16:56.633Z","dependency_job_id":null,"html_url":"https://github.com/mw99/OhhAuth","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mw99%2FOhhAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mw99%2FOhhAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mw99%2FOhhAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mw99%2FOhhAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mw99","download_url":"https://codeload.github.com/mw99/OhhAuth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223251415,"owners_count":17113763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extension","ios","oauth","swift","urlrequest"],"created_at":"2024-08-02T00:00:44.203Z","updated_at":"2024-11-09T05:30:31.592Z","avatar_url":"https://github.com/mw99.png","language":"Swift","funding_links":[],"categories":["Authentication"],"sub_categories":[],"readme":"# OhhAuth\n### Pure Swift implementation of the OAuth 1.0 protocol as an easy to use extension for the URLRequest type. [(RFC-5849)](https://tools.ietf.org/html/rfc5849])\n\nEven though its successor is already specified, the OAuth 1.0 protocol is still in wide use. This easy to use extension for the `URLRequest` type implements the most common OAuth client side request variants.\n\n\n#### Requirements\nOhhAuth depends on `libCommonCrypto` which is already installed on all common Apple operating systems (macOS, iOS, tvOS, watchOS). Unfortunately Linux is not support at the moment, but is likely to be added in the near future.\n\n\n## Usage example\n\n#### The classic usage example would be posting a tweet on Twitter:\n\nTo get the consumer credentials (key and secret) you first have to register a new Twitter app at https://apps.twitter.com\n\nThere are a lot of ways to get the user credentials (like oauth reverse authentication) but for testing the by far easiest method would be directly from your [twitter app page](https://apps.twitter.com) by using [this guide](https://dev.twitter.com/oauth/overview/application-owner-access-tokens).\n\nAlso for further information about `api.twitter.com/1.1/statuses/update.json` please refer to the [Twitter API documentation](https://dev.twitter.com/rest/reference/post/statuses/update).\n\n\n```swift\nlet cc = (key: \"\u003cYOUR APP CONSUMER KEY\u003e\", secret: \"\u003cYOUR APP CONSUMER SECRET\u003e\")\nlet uc = (key: \"\u003cYOUR USER KEY\u003e\", secret: \"\u003cYOUR USER SECRET\u003e\")\n\nvar req = URLRequest(url: URL(string: \"https://api.twitter.com/1.1/statuses/update.json\")!)\n\nlet paras = [\"status\": \"Hey Twitter! \\u{1F6A7} Take a look at this sweet UUID: \\(UUID())\"]\n\nreq.oAuthSign(method: \"POST\", urlFormParameters: paras, consumerCredentials: cc, userCredentials: uc)\n\nlet task = URLSession(configuration: .ephemeral).dataTask(with: req) { (data, response, error) in\n    \n    if let error = error {\n        print(error)\n    }\n    else if let data = data {\n        print(String(data: data, encoding: .utf8) ?? \"Does not look like an utf8 response :(\")\n    }\n}\ntask.resume()\n```\n\n## Install\n\n#### Cocoa Pods\n\nTo integrate OhhAuth into your Xcode project using CocoaPods, add it to your `Podfile`:\n\n```ruby\ntarget '\u003cyour_target_name\u003e' do\n    pod 'OhhAuth'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\nYou then will need to add `import OhhAuth` at the top of your swift source files to use the extension.\n\n\n#### Swift Package Manager\n\nTo integrate OhhAuth into your Xcode project using the swift package manager, add it as a dependency to your `Package.swift` file:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"\u003cyour_package_name\u003e\",\n    dependencies: [\n        .Package(url: \"https://github.com/mw99/OhhAuth.git\", majorVersion: 1)\n    ]\n)\n```\n\nYou then will need to add `import OhhAuth` at the top of your swift source files to use the extension.\n\n\n#### Or just copy the file into your project\n\nYou only need one file located at `Sources/OhhAuth.swift`. Just drag and drop it into the Xcode project navigator.\n\n\n\n## Interface\n\n##### As `URLRequest` extension:\n```swift\n/// Easy to use method to sign a URLRequest which includes url-form parameters with OAuth.\n/// The request needs a valid URL with all query parameters etc. included.\n/// After calling this method the HTTP header fields: \"Authorization\", \"Content-Type\" \n/// and \"Content-Length\" should not be overwritten.\n///\n/// - Parameters:\n///   - method: HTTP Method\n///   - paras: url-form parameters\n///   - consumerCredentials: consumer credentials\n///   - userCredentials: user credentials (nil if this is a request without user association)\npublic mutating func oAuthSign(method: String, urlFormParameters paras: [String: String],\n    consumerCredentials cc: OhhAuth.Credentials, userCredentials uc: OhhAuth.Credentials? = nil)\n```\n\n```swift\n/// Easy to use method to sign a URLRequest which includes plain body data with OAuth.\n/// The request needs a valid URL with all query parameters etc. included.\n/// After calling this method the HTTP header fields: \"Authorization\", \"Content-Type\"\n/// and \"Content-Length\" should not be overwritten.\n///\n/// - Parameters:\n///   - method: HTTP Method\n///   - body: HTTP request body (default: nil)\n///   - contentType: HTTP header \"Content-Type\" entry (default: nil)\n///   - consumerCredentials: consumer credentials\n///   - userCredentials: user credentials (nil if this is a request without user association)\npublic mutating func oAuthSign(method: String, body: Data? = nil, contentType: String? = nil,\n    consumerCredentials cc: OhhAuth.Credentials, userCredentials uc: OhhAuth.Credentials? = nil)\n```\n\n##### Direct access from `class OhhAuth`\n\n\n```swift\n/// Function to calculate the OAuth protocol parameters and signature ready to be added\n/// as the HTTP header \"Authorization\" entry. A detailed explanation of the procedure \n/// can be found at: [RFC-5849 Section 3](https://tools.ietf.org/html/rfc5849#section-3)\n///\n/// - Parameters:\n///   - url: Request url (with all query parameters etc.)\n///   - method: HTTP method\n///   - parameter: url-form parameters\n///   - consumerCredentials: consumer credentials\n///   - userCredentials: user credentials (nil if this is a request without user association)\n///\n/// - Returns: OAuth HTTP header entry for the Authorization field.\nopen static func calculateSignature(url: URL, method: String, parameter: [String: String],\n    consumerCredentials cc: Credentials, userCredentials uc: Credentials?) -\u003e String\n```\n\n```swift    \n/// Function to perform the right percentage encoding for url form parameters.\n///\n/// - Parameter paras: url-form parameters\n/// - Parameter encoding: used string encoding (default: .utf8)\n/// - Returns: correctly percentage encoded url-form parameters\nopen static func httpBody(forFormParameters paras: [String: String], \n    encoding: String.Encoding = .utf8) -\u003e Data?\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmw99%2FOhhAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmw99%2FOhhAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmw99%2FOhhAuth/lists"}