{"id":13338739,"url":"https://github.com/Colaski/SwAuth","last_synced_at":"2025-03-11T10:31:53.726Z","repository":{"id":45413711,"uuid":"431771303","full_name":"Colaski/SwAuth","owner":"Colaski","description":"OAuth 2.0 library using async/await written in Swift.","archived":true,"fork":false,"pushed_at":"2023-01-05T02:07:32.000Z","size":1079,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-23T22:18:45.394Z","etag":null,"topics":["async-await","device-flow","ios","macos","oauth2","oauth2-authentication","oauth2-client","oauth2-flow","pkce-flow","swauth","swift","swift-package-manager","tvos","watchos"],"latest_commit_sha":null,"homepage":"https://swauth.netlify.app/documentation/Swauth","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/Colaski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-25T08:38:34.000Z","updated_at":"2023-09-25T16:31:08.000Z","dependencies_parsed_at":"2023-02-03T05:16:51.865Z","dependency_job_id":null,"html_url":"https://github.com/Colaski/SwAuth","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colaski%2FSwAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colaski%2FSwAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colaski%2FSwAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colaski%2FSwAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Colaski","download_url":"https://codeload.github.com/Colaski/SwAuth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243015443,"owners_count":20222082,"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":["async-await","device-flow","ios","macos","oauth2","oauth2-authentication","oauth2-client","oauth2-flow","pkce-flow","swauth","swift","swift-package-manager","tvos","watchos"],"created_at":"2024-07-29T19:17:08.968Z","updated_at":"2025-03-11T10:31:52.206Z","avatar_url":"https://github.com/Colaski.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"**This repository is now archived as my time has become limited and my interest in Apple development has waned.**\n\n\u003c!-- omit in toc --\u003e\n# SwAuth [![License](https://img.shields.io/github/license/colaski/swauth?color=lightgrey\u0026style=flat-square)](https://github.com/Colaski/SwAuth#license) ![Version](https://img.shields.io/github/v/tag/colaski/swauth?label=release\u0026style=flat-square)\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b38ed7450d054e29a0381ad3c11df264)](https://app.codacy.com/gh/Colaski/SwAuth?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=Colaski/SwAuth\u0026utm_campaign=Badge_Grade_Settings)\n[![Build](https://github.com/Colaski/SwAuth/actions/workflows/build.yml/badge.svg)](https://github.com/Colaski/SwAuth/actions/workflows/build.yml)\n![SPM](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-success?style=flat-square)\n![Platforms](https://img.shields.io/badge/Platforms-iOS%2013%2B%20%7C%20macOS%2010.15%2B%20%7C%20watchOS%206%2B%20%7C%20tvOS%2013%2B-blue?style=flat-square)\n![Swift](https://img.shields.io/badge/Swift-5.5-orange?style=flat-square)\n\nSwAuth is an OAuth 2.0 HTTP request library written in Swift for iOS 13.0+, macOS 10.15+, watchOS 6.0+, and tvOS 13.0+.\n\n- [Features](#features)\n  - [Built-in Support](#built-in-support)\n- [Requirements](#requirements)\n- [Installation/Integration](#installationintegration)\n  - [Swift Package](#swift-package)\n  - [App](#app)\n- [Basic Usage](#basic-usage)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- [x] Beautiful readable syntax with async/await! Kiss completion handler hell and the closure jungle goodbye!\n- [x] Supports Authorization Code Grant (RFC 6749/6750), Proof Key for Code Exchange (PKCE) extension for Authorization Code Grant (RFC 7636), and the Device Authorization Grant (RFC 8628).\n- [x] Support for all Apple device platforms.\n- [x] Retry errored requests.\n- [x] Automatically refreshes tokens.\n- [x] Tokens stored on Keychain and cross-site request forgery mitigation by default.\n- [x] Easily deal with JSON responses with [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) built-in.\n- [x] Easily integrate with SwiftUI.\n- [x] [Complete, meticulous, thorough, documentation.](https://swauth.netlify.app/documentation/Swauth)\n- [x] Errors that are probably, maybe, useful.\n- [x] Built on [SwiftNIO](https://github.com/apple/swift-nio) with [AsyncHTTPClient](https://github.com/swift-server/async-http-client).\n- [x] QR Code for the Device Authorization Flow (tvOS/watchOS).\n- [x] Sample/Example Apps.\n- [x] Built- in support for some popular Web APIs.\n\n### Built-in Support\n\nSwAuth has build in support for some Web API's with more to come:\n\n- [Spotify](https://swauth.netlify.app/documentation/swauth/spotify)\n\n## Requirements\n\n- Xcode 13.2+\n- iOS 13.0+ | macOS 10.15+ | watchOS 6.0+ | tvOS 13.0+\n\n## Installation/Integration\n\n### Swift Package\n\nUse the Swift Package Manager to add SwAuth to your project! Simply add the package to dependencies in your `Package.swift`:\n\n```swift\n// swift-tools-version:5.5\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourPackageName\",\n    products: [\n        .library(name: \"YourPackageName\", targets: [\"YourPackageName\"]),\n    ],\n    dependencies: [\n        .package(url: \"https://github.com/Colaski/SwAuth.git\", from: \"1.0.1\"),\n    ],\n    targets: [\n        .target(name: \"YourPackageName\", dependencies: [\"SwAuth\"]),\n    ]\n)\n```\n\n### App\n\nSelect `File \u003e Add Packages` in Xcode and enter `https://github.com/Colaski/SwAuth.git`\n\nXcode should take care of the rest!\n\n## Basic Usage\n\n1. Import SwAuth in files you wish to use it's amazing features:\n\n    ```swift\n    import SwAuth\n    ```\n\n2. Create an instance of keychain:\n\n    ```swift\n    let keychain = Keychain(service: \"com.your.bundleID\",\n                            accessGroup: \"appIdentifierPrefix.com.your.bundleID\").label(\"Your App Name\")\n    ```\n\n    SwAuth uses KeychainAccess to make setting up the keychain easy. You can see a full list of options for it here: [https://github.com/kishikawakatsumi/KeychainAccess#key-configuration-accessibility-sharing-icloud-sync](https://github.com/kishikawakatsumi/KeychainAccess#key-configuration-accessibility-sharing-icloud-sync).\n\n3. Create an instance of the proper authorization flow for your Web API.\n\n    ```swift\n    let keychain = Keychain(service: \"com.your.bundleID\",\n                            accessGroup: \"appIdentifierPrefix.com.your.bundleID\").label(\"Your App Name\")\n\n    var spotify = PKCEAuthorizationFlow(clientID: \"YourClientID\",\n                                        authorizationEndpoint: URL(string: \"https://accounts.spotify.com/authorize\")!,\n                                        tokenEndpoint: URL(string: \"https://accounts.spotify.com/api/token\")!,\n                                        redirectURI: \"someapp://callback\",\n                                        keychain: keychain,\n                                        scopes: \"user-follow-modify\")\n    spotify.additionalRefreshTokenBodyParams = [\"client_id\": \"YourClientID\"] // Spotify specifically requires the client ID to be included in the refresh token's body parameters.\n    ```\n\n4. Start an ASWebAuthenticationSession like in the [example app](https://github.com/Colaski/SwAuth/blob/main/SwAuthTestApp/SwAuthTestApp/ProviderView.swift#L94) with the instance's authorization URL:\n\n    ```swift\n    spotify.authorizationURL\n    ```\n\n5. Pass the callback URL from the ASWebAuthenticationSession into the provided handler method:\n\n    ```swift\n    do {\n        try await spotify.authorizationResponseHandler(for: callbackURL)\n    } catch {\n        print(error.localizedDescription)\n    }\n    ```\n\n6. Make an authorized request:\n\n    ```swift\n    do {\n        // https://developer.spotify.com/documentation/web-api/reference/#/operations/follow-artists-users\n        var request = HTTPRequest(endpoint: URL(sting: \"https://api.spotify.com/v1/me/following\")!)\n        request.httpMethod = .PUT\n        request.endpointQueryItems = [\"type\": \"artist\"]\n        request.httpBody = [\"ids\": [\"5K4W6rqBFWDnAN6FQUkS6x\"]]\n        request.bodyEncoding = .JSON\n\n        // Send an authenticated HTTP request, this one will follow the artist Kanye West on Spotify.\n        let json = try await spotify.authenticatedRequest(for: request, numberOfRetries: 2).json()\n        \n        // Prints the JSON output\n        print(json)\n    } catch {\n        print(error.localizedDescription)\n    }\n    ```\n\nFor more information, read my beautiful documentation: [https://swauth.netlify.app/documentation/Swauth](https://swauth.netlify.app/documentation/Swauth)\n\n## Contributing\n\nCheck out [CONTRIBUTING.md](./CONTRIBUTING.md) for information!\n\n## License\n\nSwAuth its self is licensed under the [MIT License](./LICENSE), however please take notice of the [NOTICE](./NOTICE.md) file in the root of this repository. Also, make sure to check the respective licenses of this library's dependencies before releasing your project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColaski%2FSwAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FColaski%2FSwAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColaski%2FSwAuth/lists"}