{"id":813,"url":"https://github.com/delba/SwiftyOAuth","last_synced_at":"2025-08-06T14:31:30.332Z","repository":{"id":62456950,"uuid":"58314888","full_name":"delba/SwiftyOAuth","owner":"delba","description":"A simple OAuth library for iOS with a built-in set of providers","archived":false,"fork":false,"pushed_at":"2020-01-13T13:33:52.000Z","size":244,"stargazers_count":478,"open_issues_count":4,"forks_count":30,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-07-12T21:04:29.765Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delba.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":"2016-05-08T14:06:20.000Z","updated_at":"2024-06-03T10:20:51.000Z","dependencies_parsed_at":"2022-11-01T23:04:26.682Z","dependency_job_id":null,"html_url":"https://github.com/delba/SwiftyOAuth","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FSwiftyOAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FSwiftyOAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FSwiftyOAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FSwiftyOAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delba","download_url":"https://codeload.github.com/delba/SwiftyOAuth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":215505666,"owners_count":15889305,"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":[],"created_at":"2024-01-05T20:15:31.926Z","updated_at":"2024-08-17T16:31:09.718Z","avatar_url":"https://github.com/delba.png","language":"Swift","funding_links":[],"categories":["Authentication","Libs","Network [🔝](#readme)"],"sub_categories":["Network","Other free courses","Getting Started"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/delba/SwiftyOAuth/assets/SwiftyOAuth%402x.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.org/delba/SwiftyOAuth\"\u003e\u003cimg alt=\"Travis Status\" src=\"https://img.shields.io/travis/delba/SwiftyOAuth.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://img.shields.io/cocoapods/v/SwityOAuth.svg\"\u003e\u003cimg alt=\"CocoaPods compatible\" src=\"https://img.shields.io/cocoapods/v/SwiftyOAuth.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg alt=\"Carthage compatible\" src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n**SwiftyOAuth** is a *small* OAuth library with a built-in set of providers and a nice API to add your owns.\n\n```swift\nlet instagram: Provider = .instagram(clientID: \"***\", redirectURL: \"foo://callback\")\n\ninstagram.authorize { result in\n    print(result) // success(Token(accessToken: \"abc123\"))\n}\n```\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e • \u003ca href=\"#providers\"\u003eProviders\u003c/a\u003e • \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e • \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n## Usage\n\n#### Provider\n\n[`Provider.swift`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Provider.swift)\n\n##### Step 1: Create a provider\n\nInitialize a provider with the custom URL scheme that you defined:\n\n```swift\n// Provider using the server-side (explicit) flow\n\nlet provider = Provider(\n    clientID:     \"***\",\n    clientSecret: \"***\",\n    authorizeURL: \"https://example.com/authorize\",\n    tokenURL:     \"https://example.com/authorize/token\",\n    redirectURL:  \"foo://callback\"\n)\n\n// Provider using the client-side (implicit) flow\n\nlet provider = Provider(\n    clientID:     \"***\",\n    authorizeURL: \"https://example.com/authorize\",\n    redirectURL:  \"foo://callback\"\n)\n\n// Provider using the client-credentials flow\n\nlet provider = Provider(\n    clientID:     \"***\",\n    clientSecret: \"***\"\n)\n```\n\nAlternatively, you can use one of the [built-in providers](https://github.com/delba/SwiftyOAuth#providers):\n\n```swift\nlet github = .gitHub(\n    clientID:     \"***\",\n    clientSecret: \"***\",\n    redirectURL:  \"foo://callback\"\n)\n```\n\nOptionally set the `state` and `scopes` properties:\n\n```swift\ngithub.state  = \"asdfjkl;\" // An random string used to protect against CSRF attacks.\ngithub.scopes = [\"user\", \"repo\"]\n```\n\nUse a `WKWebView` if the provider doesn't support custom URL schemes as redirect URLs.\n\n```swift\nlet provider = Provider(\n    clientID:     \"***\",\n    clientSecret: \"***\",\n    authorizeURL: \"https://example.com/authorize\",\n    tokenURL:     \"https://example.com/authorize/token\",\n    redirectURL:  \"https://an-arbitrary-redirect-url/redirect\"\n)\n\nprovider.useWebView = true\n```\n\nDefine additional parameters for the authorization request or the token request with `additionalAuthRequestParams` and `additionalTokenRequestParams` respectively:\n\n```swift\ngithub.additionalAuthRequestParams[\"allow_signup\"] = \"false\"\n```\n\n##### Step 2: Handle the incoming requests\n\nHandle the incoming requests in your `AppDelegate`:\n\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n    github.handleURL(url, options: options)\n\n    return true\n}\n```\n\n##### Step 3: Ask for authorization\n\nFinally, ask for authorization. SwiftyOAuth will either present a `SFSafariViewController` (iOS 9) or open mobile safari.\n\n```swift\ngithub.authorize { (result: Result\u003cToken, Error\u003e) -\u003e Void in\n    switch result {\n    case .success(let token): print(token)\n    case .failure(let error): print(error)\n    }\n}\n```\n\nIf the provider provides an expirable token, you may want to refresh it.\n\n```swift\nlet uber: Provider = .uber(\n    clientID: \"***\",\n    clientSecret: \"***\",\n    redirectURL: \"foo://callback/uber\"\n)\n\n// uber.token!.isExpired =\u003e true\n\nuber.refreshToken { result in\n    switch result {\n    case .success(let token): print(token)\n    case .failure(let error): print(error)\n    }\n}\n```\n\n#### Token\n\n[`Token.swift`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Token.swift)\n\nThe `access_token`, `token_type`, `scopes`, and informations related to the expiration are available as `Token` properties:\n\n```swift\ntoken.accessToken // abc123\ntoken.tokenType   // .Bearer\ntoken.scopes      // [\"user\", \"repo\"]\n\ntoken.expiresIn // 123\ntoken.isExpired // false\ntoken.isValid   // true\n```\n\nAdditionally, you can access all the token data via the `dictionary` property:\n\n```swift\ntoken.dictionary // [\"access_token\": \"abc123\", \"token_type\": \"bearer\", \"scope\": \"user repo\"]\n```\n\n#### Token Store\n\nEvery `Token` is stored and retrieved through an object that conforms to the `TokenStore` protocol.\n\nThe library currently supports following `TokenStore`s:\n\n```swift\nprovider.tokenStore = Keychain.shared\n```\n\n**`Keychain`**: Before you use this`TokenStore`, make sure you turn on the *Keychain Sharing* capability.\n\n```swift\nprovider.tokenStore = UserDefault.standard\n```\n\n**`UserDefaults`**: the default `TokenStore`. Information are saved locally and, if properly initialized, to your *App Group*.\n\n```swift\nprovider.tokenStore = NSUbiquitousKeyValueStore.default\n```\n\n**`NSUbiquitousKeyValueStore`**: the information are saved in the *iCloud Key Value Store*. Before you use this `TokenStore` make sure your project has been properly configured as described [here](https://developer.apple.com/library/mac/documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html#//apple_ref/doc/uid/TP40012094-CH6-SW26).\n\n#### Error\n\n[`Error.swift`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Error.swift)\n\n**Error** is a enum that conforms to the `ErrorType` protocol.\n\n- `cancel` The user cancelled the authorization process by closing the web browser window.\n\n- `applicationSuspended` The OAuth application you set up has been suspended.\n\n- `redirectURIMismatch` The provided `redirectURL` that doesn't match what you've registered with your application.\n\n- `accessDenied` The user rejects access to your application.\n\n- `invalidClient` The `clientID` and or `clientSecret` you passed are incorrect.\n\n- `invalidGrant` The verification code you passed is incorrect, expired, or doesn't match what you received in the first request for authorization.\n\n- `other` The application emitted a response in the form of `{\"error\": \"xxx\", \"error_description\": \"yyy\"}` but SwiftyOAuth doesn't have a enum for it. The data is available in the associated values.\n\n- `unknown` The application emitted a response that is neither in the form of a success one (`{\"access_token\": \"xxx\"...}`) nor in the form of a failure one (`{\"error\": \"xxx\"...}`). The data is available in the associated value.\n\n- `nsError` An error triggered when making network requests or parsing JSON. The data is available in the associated value.\n\n#### Providers\n\n[`Providers/`](https://github.com/delba/SwiftyOAuth/tree/master/Source/Providers)\n\n- [`GitHub`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/GitHub.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/GitHub)\n- [`Dribbble`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Dribbble.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Dribbble)\n- [`Instagram`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Instagram.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Instagram)\n- [`Uber`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Uber.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Uber)\n- [`Feedly`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Feedly.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Feedly)\n- [`Vimeo`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Vimeo.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Vimeo)\n- [`SoundCloud`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/SoundCloud.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/SoundCloud)\n- [`StackExchange`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/StackExchange.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/StackExchange)\n- [`Medium`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Medium.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Medium)\n- [`Foursquare`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Foursquare.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Foursquare)\n- [`Stripe`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Stripe.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Stripe)\n- [`Reddit`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Reddit.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Reddit)\n- [`Weibo`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Weibo.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Weibo)\n- [`Slack`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Slack.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Slack)\n- [`Dropbox`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Dropbox.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Dropbox)\n- [`Basecamp`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Basecamp.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Basecamp)\n- [`Spotify`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Spotify.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Spotify)\n- [`Meetup`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Meetup.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Meetup)\n- [`Strava`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Strava.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Strava)\n- [`Google`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Google.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Google)\n- [`Stuart`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/Stuart.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/Stuart)\n- [`UberRUSH`](https://github.com/delba/SwiftyOAuth/blob/master/Source/Providers/UberRUSH.swift) - [**doc**](https://github.com/delba/SwiftyOAuth/wiki/UberRUSH)\n- *More to come...*\n\nCheck the [**wiki**](https://github.com/delba/SwiftyOAuth/wiki) for more informations!\n\n## Installation\n\n#### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate **SwiftyOAuth** into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"delba/SwiftyOAuth\" \u003e= 1.1\n```\n\n#### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects.\n\nYou can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate **SwiftyOAuth** into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nuse_frameworks!\n\npod 'SwiftyOAuth', '~\u003e 1.1'\n```\n\n## License\n\nCopyright (c) 2016-2019 Damien (http://delba.io)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelba%2FSwiftyOAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelba%2FSwiftyOAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelba%2FSwiftyOAuth/lists"}