{"id":13340076,"url":"https://github.com/codefiesta/OAuthKit","last_synced_at":"2025-03-11T16:32:04.275Z","repository":{"id":242000019,"uuid":"807399388","full_name":"codefiesta/OAuthKit","owner":"codefiesta","description":"A Swift Package for OAuth 2.0 ","archived":false,"fork":false,"pushed_at":"2025-01-08T18:16:26.000Z","size":55,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T16:11:26.648Z","etag":null,"topics":["ios","macos","oauth2","swift","swift-package-manager","swiftui","visionos"],"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/codefiesta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-29T03:10:07.000Z","updated_at":"2025-01-08T18:16:28.000Z","dependencies_parsed_at":"2024-05-31T04:23:15.155Z","dependency_job_id":"3b36fc0f-3369-467c-bb60-a6541f2db46e","html_url":"https://github.com/codefiesta/OAuthKit","commit_stats":null,"previous_names":["codefiesta/oauthkit"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codefiesta%2FOAuthKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codefiesta%2FOAuthKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codefiesta%2FOAuthKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codefiesta%2FOAuthKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codefiesta","download_url":"https://codeload.github.com/codefiesta/OAuthKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243070388,"owners_count":20231444,"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":["ios","macos","oauth2","swift","swift-package-manager","swiftui","visionos"],"created_at":"2024-07-29T19:22:07.465Z","updated_at":"2025-03-11T16:31:59.230Z","avatar_url":"https://github.com/codefiesta.png","language":"Swift","readme":"![Build](https://github.com/codefiesta/OAuthKit/actions/workflows/swift.yml/badge.svg)\n![Xcode 16.0+](https://img.shields.io/badge/Xcode-16.0%2B-gold.svg)\n![Swift 6.0+](https://img.shields.io/badge/Swift-6.0%2B-tomato.svg)\n![iOS 17.0+](https://img.shields.io/badge/iOS-17.0%2B-crimson.svg)\n![macOS 15.0+](https://img.shields.io/badge/macOS-15.0%2B-skyblue.svg)\n![visionOS 1.0+](https://img.shields.io/badge/visionOS-1.0%2B-magenta.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-indigo.svg)](https://opensource.org/licenses/MIT)\n\n# OAuthKit\n\nOAuthKit is a modern, event-driven Swift Package that leverages the [Combine](https://developer.apple.com/documentation/combine) Framework to publish [OAuth 2.0](https://oauth.net/2/) events which allows application developers to easily configure OAuth Providers and focus on making great applications instead of focusing on the details of authorization flows.\n\n## OAuthKit Usage\n\nThe following is an example of the simplest usage of using OAuthKit in macOS:\n\n```swift\nimport OAuthKit\nimport SwiftUI\n\n@main\nstruct OAuthApp: App {\n\n    @Environment(\\.oauth)\n    var oauth: OAuth\n\n    /// Build the scene body\n    var body: some Scene {\n\n        WindowGroup {\n            ContentView()\n        }.environmentObject(oauth)\n        \n        WindowGroup(id: \"oauth\") {\n            OAWebView()\n        }.environmentObject(oauth)\n    }\n} \n\nstruct ContentView: View {\n    \n    @Environment(\\.openWindow)\n    var openWindow\n    \n    @Environment(\\.dismissWindow)\n    private var dismissWindow\n    \n    @EnvironmentObject\n    var oauth: OAuth\n\n    var body: some View {\n        VStack {\n            switch oauth.state {\n            case .empty:\n                providerList\n            case .authorizing(let provider):\n                Text(\"Authorizing [\\(provider.id)]\")\n            case .requestingAccessToken(let provider):\n                Text(\"Requesting Access Token [\\(provider.id)]\")\n            case .authorized(let auth):\n                Button(\"Authorized [\\(auth.provider.id)]\") {\n                    oauth.clear()\n                }\n            }\n        }\n        .onReceive(oauth.$state) { state in\n            handle(state: state)\n        }\n    }\n    \n    /// Displays a list of oauth providers.\n    var providerList: some View {\n        List(oauth.providers) { provider in\n            Button(provider.id) {\n                // Start the authorization flow\n                oauth.authorize(provider: provider)\n            }\n        }\n    }\n    \n    /// Reacts to oauth state changes by opening or closing authorization windows.\n    /// - Parameter state: the published state change\n    private func handle(state: OAuth.State) {\n        switch state {\n        case .empty, .requestingAccessToken:\n            break\n        case .authorizing(let provider):\n            openWindow(id: \"oauth\")\n        case .authorized(_):\n            dismissWindow(id: \"oauth\")\n        }\n    }\n}\n```\n## OAuthKit Configuration\nBy default, the easiest way to configure OAuthKit is to simply drop an `oauth.json` file into your main bundle and it will get automatically loaded into your swift application and available as an [EnvironmentObject](https://developer.apple.com/documentation/swiftui/environmentobject). You can find an example `oauth.json` file [here](https://github.com/codefiesta/OAuthKit/blob/main/Tests/OAuthKitTests/Resources/oauth.json).\n\n```swift\n    @EnvironmentObject\n    var oauth: OAuth\n```\n\nIf you want to customize your OAuth environment or are using modules in your application, you can also specify which bundle to load configure files from:\n\n\n```swift\n    let oauth: OAuth = .init(.module)\n```\n\nIf you are building your OAuth Providers programatically (recommended for production applications via a CI build pipeline for security purposes), you can pass providers and options as well.\n\n```swift\n    let providers: [OAuth.Provider] = ...\n    let options: [OAuth.Option: Any] = [.applicationTag: \"com.bundle.identifier\"]\n    let oauth: OAuth = .init(providers: providers, options: options)\n```\n\n\n## Security Best Practices\nAlthough OAuthKit will automatically try to load the `oauth.json` file found inside your main bundle (or bundle passed to the initializer) for convenience purposes, it is good policy to **NEVER** check in **clientID** or **clientSecret** values into source control. Also, it is possible for someone to [inspect and reverse engineer](https://www.nowsecure.com/blog/2021/09/08/basics-of-reverse-engineering-ios-mobile-apps/) the contents of your app and look at any files inside your app bundle which means you could potentially expose these secrets in the `oauth.json` file. The most secure way to protect OAuth secrets is to build your Providers programatically and bake [secret values](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) into your code via your CI pipeline.\n\n## OAuth Providers\n* [Github](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps)\n* [Google](https://developers.google.com/identity/protocols/oauth2)\n* [Instagram](https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions)\n* [Microsoft](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow)\n* [Slack](https://api.slack.com/authentication/oauth-v2)\n* [Twitter](https://developer.x.com/en/docs/authentication/oauth-2-0)\n\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Auth"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodefiesta%2FOAuthKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodefiesta%2FOAuthKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodefiesta%2FOAuthKit/lists"}