{"id":19773159,"url":"https://github.com/ibm-cloud-security/appid-clientsdk-swift","last_synced_at":"2025-04-30T18:31:35.501Z","repository":{"id":48979861,"uuid":"75317243","full_name":"ibm-cloud-security/appid-clientsdk-swift","owner":"ibm-cloud-security","description":null,"archived":false,"fork":false,"pushed_at":"2021-06-03T13:53:59.000Z","size":1175,"stargazers_count":7,"open_issues_count":8,"forks_count":12,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-03-15T08:21:57.858Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ibm-cloud-security.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-12-01T17:43:51.000Z","updated_at":"2023-08-02T04:50:02.000Z","dependencies_parsed_at":"2022-08-30T08:01:14.396Z","dependency_job_id":null,"html_url":"https://github.com/ibm-cloud-security/appid-clientsdk-swift","commit_stats":null,"previous_names":["ibm-bluemix-mobile-services/appid-clientsdk-swift"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibm-cloud-security%2Fappid-clientsdk-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibm-cloud-security%2Fappid-clientsdk-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibm-cloud-security%2Fappid-clientsdk-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibm-cloud-security%2Fappid-clientsdk-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibm-cloud-security","download_url":"https://codeload.github.com/ibm-cloud-security/appid-clientsdk-swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224219621,"owners_count":17275477,"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-11-12T05:08:50.315Z","updated_at":"2024-11-12T05:08:50.761Z","avatar_url":"https://github.com/ibm-cloud-security.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IBM Cloud App ID iOS Swift SDK\n\n[![IBM Cloud powered][img-ibmcloud-powered]][url-ibmcloud]\n[![Travis][img-travis-master]][url-travis-master]\n[![Coveralls][img-coveralls-master]][url-coveralls-master]\n[![Codacy][img-codacy]][url-codacy]\n[![License][img-license]][url-bintray]\n\n[![GithubWatch][img-github-watchers]][url-github-watchers]\n[![GithubStars][img-github-stars]][url-github-stars]\n[![GithubForks][img-github-forks]][url-github-forks]\n\n## Requirements\n* Xcode 9.0 or above\n* CocoaPods 1.1.0 or higher\n* MacOS 10.11.5 or higher\n* iOS 10.0 or higher\n\n## Installing the SDK:\n\n1. Add the 'IBMCloudAppID' dependency to your Podfile, for example:\n\n    ```swift\n    target \u003cyourTarget\u003e do\n       use_frameworks!\n\t     pod 'IBMCloudAppID'\n    end\n    ```  \n2. From the terminal, run:  \n    ```swift\n    pod install --repo-update\n    ```\n\n## Initializing the App ID client SDK\n1. Open your Xcode project and enable Keychain Sharing (Under project settings \u003e Capabilities \u003e Keychain sharing)\n2. Under project setting \u003e info \u003e Url Types, Add $(PRODUCT_BUNDLE_IDENTIFIER) as a URL Scheme\n3. Add the following import to your AppDelegate.swift file:\n\t```swift\n\timport IBMCloudAppID\n\t```\n4. Initialize the client SDK by passing the tenantId and region parameters to the initialize method. A common, though not mandatory, place to put the initialization code is in the application:didFinishLaunchingWithOptions: method of the AppDelegate in your Swift application.\n    ```swift\n    AppID.sharedInstance.initialize(tenantId: \u003ctenantId\u003e, region: AppID.REGION_UK)\n    ```\n    * Replace \"tenantId\" with the App ID service tenantId.\n    * Replace the `AppID.REGION_UK` with the your App ID region (`AppID.REGION_US_SOUTH`, `AppID.REGION_SYDNEY`).\n\n5. Add the following code to you AppDelegate file\n    ```swift\n    func application(_ application: UIApplication, open url: URL, options :[UIApplicationOpenURLOptionsKey : Any]) -\u003e Bool {\n        return AppID.sharedInstance.application(application, open: url, options: options)\n    }\n    ```\n\n## Using the Login Widget\nAfter the App ID client SDK is initialized, you can start authenticating users by launching the Login Widget.\n1. Add the following import to the file in which you want to use with the login Widget:\n```swift\nimport IBMCloudAppID\n```\n2. Add the following code to the same file:\n```swift\nclass delegate : AuthorizationDelegate {\n    public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n        //User authenticated\n    }\n\n    public func onAuthorizationCanceled() {\n        //Authentication canceled by the user\n    }\n\n    public func onAuthorizationFailure(error: AuthorizationError) {\n        //Exception occurred\n    }\n}\n\nAppID.sharedInstance.loginWidget?.launch(delegate: delegate())\n```\n**Note**:\n* By default, App ID is configured to use Facebook, Google, and Cloud Directory as identity providers. If you change your identity provider settings to provide only one option, then the Login Widget is not needed and will not display. The user is directed to your chosen identity provider's authentication screen.\n* When using Cloud Directory, and \"Email verification\" is configured to *not* allow users to sign-in without email verification, then the \"onAuthorizationSuccess\" of the \"AuthorizationListener\" will be invoked without tokens.\n\n\n## Managing Cloud Directory with the iOS Swift SDK\n\n\n### Sign in using Resource Owner Password\n\nYou can obtain access token and id token by supplying the end user's username and the end user's password.\n  ```swift\n  class delegate : TokenResponseDelegate {\n      public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n      //User authenticated\n      }\n\n      public func onAuthorizationFailure(error: AuthorizationError) {\n      //Exception occurred\n      }\n  }\n\n  AppID.sharedInstance.signinWithResourceOwnerPassword(username: username, password: password, delegate: delegate())\n  ```\n\n### Sign in with refresh token\n\nIt is recommended to store the refresh token locally such that it will be possible to sign in with the refresh token without requiring the user to type his credentials again.\n  ```swift\n  class delegate : TokenResponseDelegate {\n      public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n      //User authenticated\n      }\n\n      public func onAuthorizationFailure(error: AuthorizationError) {\n      //Exception occurred\n      }\n  }\n\n  AppID.sharedInstance.signInWithRefreshToken(refreshTokenString: refreshTokenString, delegate: delegate())\n  ```\n\n\n### Sign Up\n\nMake sure to set **Allow users to sign up and reset their password** to **ON**, in the settings for Cloud Directory.\n\nUse LoginWidget class to start the sign up flow.\n```swift\nclass delegate : AuthorizationDelegate {\n  public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n     if accessToken == nil \u0026\u0026 identityToken == nil {\n      //email verification is required\n      return\n     }\n   //User authenticated\n  }\n\n  public func onAuthorizationCanceled() {\n      //Sign up canceled by the user\n  }\n\n  public func onAuthorizationFailure(error: AuthorizationError) {\n      //Exception occurred\n  }\n}\n\nAppID.sharedInstance.loginWidget?.launchSignUp(delegate: delegate())\n```\n### Forgot Password\nMake sure to set **Allow users to sign up and reset their password** and **Forgot password email** to **ON**, in the settings for Cloud Directory.\n\nUse LoginWidget class to start the forgot password flow.\n```swift\nclass delegate : AuthorizationDelegate {\n   public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n      //forgot password finished, in this case accessToken and identityToken will be null.\n   }\n\n   public func onAuthorizationCanceled() {\n       //forgot password canceled by the user\n   }\n\n   public func onAuthorizationFailure(error: AuthorizationError) {\n       //Exception occurred\n   }\n}\n\nAppID.sharedInstance.loginWidget?.launchForgotPassword(delegate: delegate())\n```\n### Change Details\n\nMake sure to set **Allow users to sign up and reset their password** to **ON**, in the settings for Cloud Directory.\n\nUse LoginWidget class to start the change details flow.\nThis API can be used only when the user is logged in using Cloud Directory identity provider.\n```swift\n\n class delegate : AuthorizationDelegate {\n     public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n        //User authenticated, and fresh tokens received\n     }\n\n     public func onAuthorizationCanceled() {\n         //changed details canceled by the user\n     }\n\n     public func onAuthorizationFailure(error: AuthorizationError) {\n         //Exception occurred\n     }\n }\n\n AppID.sharedInstance.loginWidget?.launchChangeDetails(delegate: delegate())\n```\n\n### Change Password\n\nMake sure to set **Allow users to sign up and reset their password** to **ON**, in the settings for Cloud Directory.\n\nUse LoginWidget class to start the change password flow.\nThis API can be used only when the user is logged in using Cloud Directory identity provider.\n```swift\n class delegate : AuthorizationDelegate {\n     public func onAuthorizationSuccess(accessToken: AccessToken?, identityToken: IdentityToken?, refreshToken: RefreshToken?, response:Response?) {\n         //User authenticated, and fresh tokens received\n     }\n\n     public func onAuthorizationCanceled() {\n         //change password canceled by the user\n     }\n\n     public func onAuthorizationFailure(error: AuthorizationError) {\n          //Exception occurred\n     }\n  }\n\n  AppID.sharedInstance.loginWidget?.launchChangePassword(delegate: delegate())\n```\n\n### Logout\nCall the logout function in order to clear the stored tokens.\n```swift\n AppID.sharedInstance.logout()\n```\n\n### User Profile\n\nUsing the App ID UserProfileManager, you are able to create, read, and delate attributes in a user's profile as well as retrieve additional info about a user.\n\n```swift\n\nlet key = \"attrKey\"\nlet value = \"attrValue\"\nlet accessToken = \"\u003caccess token\u003e\"\nlet idToken = \"\u003cid token\u003e\"\n\nlet userProfileManager = AppID.sharedInstance.userProfileManager\n\n// Handle attribute response\nfunc attributeHandler(error: Error?, response: [String: Any]) {}\n\n/// If no tokens are passed, App ID will attempt to use the latest stored access and identity tokens\n\n// Set Attributes\nuserProfileManager?.setAttribute(key: key, value: value, completionHandler: attributeHandler)\nuserProfileManager?.setAttribute(key: key, value: value, accessTokenString: accessToken)\n\n// Get particular attribute\nuserProfileManager?.getAttribute(key: key, completionHandler: attributeHandler)\nuserProfileManager?.getAttribute(key: key, accessTokenString: accessToken, completionHandler: attributeHandler)\n\n// Get all attributes\nuserProfileManager?.getAttributes(completionHandler: attributeHandler)\nuserProfileManager?.getAttributes(accessTokenString: accessToken, completionHandler: attributeHandler)\n\n// Delete an Attribute\nuserProfileManager?.deleteAttribute(key: key, completionHandler:attributeHandler)\nuserProfileManager?.deleteAttribute(key: key, accessTokenString: accessToken, completionHandler: attributeHandler)\n\n// Retrieve additional information about a user using the stored access/identity tokens\nuserProfileManager?.getUserInfo { (error: Error?, info: [String: Any]?) in\n\n}\n\n// Retrieve additional information about a user using the provided access and identity token\n// If an identityToken is provided (recommended), we will validate the user info response\nuserProfileManager?.getUserInfo(accessTokenString: accessToken, identityTokenString: idToken { (error: Error?, info: [String: Any]?) in\n\n}\n```\n\n## Invoking protected resources\nAdd the following imports to the file in which you want to invoke a protected resource request:\n```swift\nimport BMSCore\nimport IBMCloudAppID\n```\nThen add the following code:\n```swift\nBMSClient.sharedInstance.initialize(region: AppID.REGION_UK)\nBMSClient.sharedInstance.authorizationManager = AppIDAuthorizationManager(appid:AppID.sharedInstance)\nvar request:Request =  Request(url: \"\u003cyour protected resource url\u003e\")\nrequest.send(completionHandler: {(response:Response?, error:Error?) in\n    //code handling the response here\n})\n```\n\n## Setting Keychain Accessibility\nIn a rare case your application requires refreshing App ID tokens while running in the background you can use this API to set the required keychain permissions.\n```\nAppID.secAttrAccess = .accessibleAlways\n```\n\n## Got Questions?\nJoin us on [Slack](https://www.ibm.com/cloud/blog/announcements/get-help-with-ibm-cloud-app-id-related-questions-on-slack) and chat with our dev team.\n\n## License\nThis package contains code licensed under the Apache License, Version 2.0 (the \"License\"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 and may also view the License in the LICENSE file within this package.\n\n[img-ibmcloud-powered]: https://img.shields.io/badge/ibm%20cloud-powered-blue.svg\n[url-ibmcloud]: https://www.ibm.com/cloud/\n[url-bintray]: https://bintray.com/ibmcloudsecurity/appid-clientsdk-swift\n[img-license]: https://img.shields.io/github/license/ibm-cloud-security/appid-clientsdk-swift.svg\n[img-version]: https://img.shields.io/bintray/v/ibmcloudsecurity/maven/appid-clientsdk-swift.svg\n\n[img-github-watchers]: https://img.shields.io/github/watchers/ibm-cloud-security/appid-clientsdk-swift.svg?style=social\u0026label=Watch\n[url-github-watchers]: https://github.com/ibm-cloud-security/appid-clientsdk-swift/watchers\n[img-github-stars]: https://img.shields.io/github/stars/ibm-cloud-security/appid-clientsdk-swift.svg?style=social\u0026label=Star\n[url-github-stars]: https://github.com/ibm-cloud-security/appid-clientsdk-swift/stargazers\n[img-github-forks]: https://img.shields.io/github/forks/ibm-cloud-security/appid-clientsdk-swift.svg?style=social\u0026label=Fork\n[url-github-forks]: https://github.com/ibm-cloud-security/appid-clientsdk-swift/network\n\n[img-travis-master]: https://travis-ci.org/ibm-cloud-security/appid-clientsdk-swift.svg?branch=master\n[url-travis-master]: https://travis-ci.org/ibm-cloud-security/appid-clientsdk-swift?branch=master\n\n[img-coveralls-master]: https://coveralls.io/repos/github/ibm-cloud-security/appid-clientsdk-swift/badge.svg\n[url-coveralls-master]: https://coveralls.io/github/ibm-cloud-security/appid-clientsdk-swift\n\n[img-codacy]: https://api.codacy.com/project/badge/Grade/d41f8f069dd343769fcbdb55089561fc\n[url-codacy]: https://www.codacy.com/app/ibm-cloud-security/appid-clientsdk-swift\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibm-cloud-security%2Fappid-clientsdk-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibm-cloud-security%2Fappid-clientsdk-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibm-cloud-security%2Fappid-clientsdk-swift/lists"}