{"id":27627518,"url":"https://github.com/fusionauth/fusionauth-swift-sdk","last_synced_at":"2025-04-23T13:55:02.575Z","repository":{"id":259472445,"uuid":"781374730","full_name":"FusionAuth/fusionauth-swift-sdk","owner":"FusionAuth","description":"Swift SDK for iOS with FusionAuth","archived":false,"fork":false,"pushed_at":"2025-04-14T13:18:47.000Z","size":435,"stargazers_count":0,"open_issues_count":5,"forks_count":1,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-20T16:09:27.818Z","etag":null,"topics":["authentication","ios","oauth","oidc"],"latest_commit_sha":null,"homepage":"https://fusionauth.io","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FusionAuth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-04-03T09:04:19.000Z","updated_at":"2025-04-08T20:09:42.000Z","dependencies_parsed_at":"2024-11-04T16:24:04.536Z","dependency_job_id":"87446e3f-fe2f-4113-9222-8a226c957df8","html_url":"https://github.com/FusionAuth/fusionauth-swift-sdk","commit_stats":null,"previous_names":["sonderformat-llc/fusionauth-swift-sdk"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-swift-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-swift-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-swift-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FusionAuth%2Ffusionauth-swift-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FusionAuth","download_url":"https://codeload.github.com/FusionAuth/fusionauth-swift-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250444585,"owners_count":21431671,"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":["authentication","ios","oauth","oidc"],"created_at":"2025-04-23T13:55:01.930Z","updated_at":"2025-04-23T13:55:02.568Z","avatar_url":"https://github.com/FusionAuth.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Release Tag](https://badgen.net/github/tag/fusionauth/fusionauth-swift-sdk)](https://github.com/FusionAuth/fusionauth-swift-sdk/tags)\n[![Dependabot](https://badgen.net/github/dependabot/fusionauth/fusionauth-swift-sdk)](https://github.com/FusionAuth/fusionauth-swift-sdk/network/updates)\n[![Open PRs](https://badgen.net/github/open-prs/fusionauth/fusionauth-swift-sdk)](https://github.com/FusionAuth/fusionauth-swift-sdk/pulls)\n\nAn SDK for using FusionAuth in iOS Apps.\n\n# Table of Contents\n\n- [Overview](#overview)\n\n- [Getting Started](#getting-started)\n\n- [Usage](#usage)\n\n- [Example App](#example-app)\n\n- [Quickstart](#quickstart)\n\n- [Documentation](#documentation)\n\n- [Contributing](#contributing)\n\n- [Upgrade Policy](#upgrade-policy)\n\n\u003c!--\nthis and following tags, and the corresponding end tag, are used to delineate what is pulled into the FusionAuth docs site (the client libraries pages). Don't remove unless you also change the docs site.\n\nPlease also use ``` instead of indenting for code blocks. The backticks are translated correctly to adoc format.\n--\u003e\n\n# Overview\n\u003c!--\ntag::forDocSiteOverview[]\n--\u003e\nThis SDK allows you to use OAuth 2.0 and OpenId Connect functionality in an iOS app with FusionAuth as the\nauthorization server. It also provides a Token Manager to store, refresh, and retrieve tokens.\n\nIt's a highly standardized and simplified starting point for developers to easily integrate FusionAuth into their own custom mobile apps by taking care of all the dependencies.\n\nFollowing OAuth 2.0 and OpenID Connect functionality are covered:\n- OAuth 2.0 Authorization Code Grant\n- OAuth 2.0 Refresh Token Grant\n- OpenID Connect UserInfo\n- OpenID Connect End Session\n\n[AppAuth-iOS](https://github.com/openid/AppAuth-iOS) is used for the OAuth 2.0 Authorization Code Grant flow and OpenID Connect functionality.\n\nThe SDK is written in Swift and compatible with Object-C.\n\u003c!--\nend::forDocSiteOverview[]\n--\u003e\n\n# Getting Started\n\n\u003c!--\ntag::forDocSiteGettingStarted[]\n--\u003e\nTo use the FusionAuth iOS SDK, add this repository as a dependency.\n\nBy default the SDK uses the `FusionAuth.plist` file in the main bundle to read the configuration. The file should contain the following keys:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003c!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"\u003e\n\u003cplist version=\"1.0\"\u003e\n\u003cdict\u003e\n    \u003ckey\u003eadditionalScopes\u003c/key\u003e\n    \u003carray\u003e\n        \u003cstring\u003eprofile\u003c/string\u003e\n        \u003cstring\u003eemail\u003c/string\u003e\n    \u003c/array\u003e\n    \u003ckey\u003efusionAuthUrl\u003c/key\u003e\n    \u003cstring\u003ehttp://localhost:9011\u003c/string\u003e\n    \u003ckey\u003eclientId\u003c/key\u003e\n    \u003cstring\u003ee9fdb985-9173-4e01-9d73-ac2d60d1dc8e\u003c/string\u003e\n\u003c/dict\u003e\n\u003c/plist\u003e\n```\n\nThen, initialize the AuthorizationManager in the `init` func of your app:\n\n```swift\n@main\nstruct QuickstartApp: App {\n    init() {\n        AuthorizationManager.instance.initialize()\n    }\n}\n```\n\nBy default, the SDK uses the `MemoryStorage for storing tokens. You can use one of the other available mechanisms `KeyChainStorage`or `UserDefaultsStorage` by e.g. adding the `storage` key with the value `keychain` or `userdefaults`.\n\nAs a alternative, you can also use the `initialize` function to provide the configuration:\n\n```swift\n@main\nstruct QuickstartApp: App {\n    init() {\n        AuthorizationManager.instance.initialize(configuration: AuthorizationConfiguration(\n            clientId: \"e9fdb985-9173-4e01-9d73-ac2d60d1dc8e\",\n            fusionAuthUrl: \"http://localhost:9011\",\n            additionalScopes: [\"email\", \"profile\"]))\n    }\n}\n```\n\nFinally, instruct the app to handle the callback from the browser:\n\n```swift\n@main\nstruct QuickstartApp: App {\n    init() {\n        AuthorizationManager.instance.initialize()\n    }\n\n    var body: some Scene {\n        WindowGroup {\n            ContentView()\n                .onOpenURL { url in\n                    OAuthAuthorization.resume(with: url)\n                }\n        }\n    }\n}\n```\n\n\u003c!--\nend::forDocSiteGettingStarted[]\n--\u003e\n\n# Usage\n\n\u003c!--\ntag::forDocSiteUsage[]\n--\u003e\nTo start the OAuth 2.0 Authorization Code Grant, you can use the `oauth()` function on the `AuthorizationManager` to\nretrieve the `OAuthAuthorizationService`:\n\n```swift\ndo {\n    try await AuthorizationManager\n        .oauth()\n        .authorize(options: OAuthAuthorizeOptions())\n} catch let error as NSError {\n    print(\"Error: \\(error.localizedDescription)\")\n}\n```\n\nThe `authorize` method will open the Safari browser and redirect to the FusionAuth login page. After successful login, the user will be redirected back to the app with the authorization code. The SDK will exchange the authorization code for an access token and refresh token.\n\nThis will retrieve the authorization response, validates the `state` if it was provided, and exchanges the authorization\ncode for an access token.\nThe result of the exchange will be stored in the `TokenManager`.\n\nAfter the user is authorized, you can use `getUserInfo()` to retrieve the [User Info](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo):\n\n```swift\ndo {\n    self.userInfo = try await AuthorizationManager\n        .oauth()\n        .userInfo()\n} catch let error as NSError {\n    print(\"JSON decode failed: \\(error.localizedDescription)\")\n}\n```\n\nTo call your API with an access token, you can use the `AuthorizationManager` to retrieve a valid access token:\n\n```swift\nlet accessToken = AuthorizationManager.oauth().freshAccessToken()\n```\n\nThis will retrieve a fresh access token from the `TokenManager` and return it. If the access token is expired,\nthe `TokenManager` will refresh it automatically.\n\nFinally, you can use the `AuthorizationManager` to sign out the user and remove the tokens from the `TokenManager`:\n\n```swift\ndo {\n    try await AuthorizationManager\n        .oauth()\n        .logout(options: OAuthLogoutOptions())\n} catch let error as NSError {\n    print(\"Error: \\(error.localizedDescription)\")\n}\n```\n\nIf the user is signed out, the auth state will be cleared.\n\u003c!--\nend::forDocSiteUsage[]\n--\u003e\n\n# Example App\n\n\u003c!--\ntag::forDocSiteExampleApp[]\n--\u003e\nSee the [FusionAuth iOS SDK Example](https://github.com/FusionAuth/fusionauth-quickstart-swift-ios-native) for a functional example of an iOS client that uses the SDK.\n\u003c!--\nend::forDocSiteExampleApp[]\n--\u003e\n\n# Quickstart\n\n\u003c!--\ntag::forDocSiteQuickstart[]\n--\u003e\nSee the [FusionAuth iOS Quickstart](https://fusionauth.io/docs/quickstarts/quickstart-swift-ios-native/) for a full tutorial on using FusionAuth and iOS.\n\u003c!--\nend::forDocSiteQuickstart[]\n--\u003e\n\n# Documentation\n\n\u003c!--\ntag::forDocSiteDocumentation[]\n--\u003e\nSee the latest [Full library documentation](https://github.com/FusionAuth/fusionauth-swift-sdk/blob/main/Documentation/Reference/README.md) for the complete documentation of the SDK.\n\u003c!--\nend::forDocSiteDocumentation[]\n--\u003e\n\n# Contributing\n\u003c!--\ntag::forDocSiteContributing[]\n--\u003e\nWe hope you love using FusionAuth Swift SDK, but in case you encounter a bug or an issue with the SDK, please do let us know.\n\nPlease follow the detailed [Contributing](CONTRIBUTING.md) documentation.\n\u003c!--\nend::forDocSiteContributing[]\n--\u003e\n\n# Upgrade Policy\n\nThis library may periodically receive updates with bug fixes, security patches, tests, code samples, or documentation changes.\n\nThese releases may also update dependencies, language engines, and operating systems, as we\\'ll follow the deprecation and sunsetting policies of the underlying technologies that the libraries use.\n\nThis means that after a dependency (e.g. language, framework, or operating system) is deprecated by its maintainer, this library will also be deprecated by us, and may eventually be updated to use a newer version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-swift-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffusionauth%2Ffusionauth-swift-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffusionauth%2Ffusionauth-swift-sdk/lists"}