{"id":28227181,"url":"https://github.com/desp0o/izzisession","last_synced_at":"2025-07-06T00:09:05.397Z","repository":{"id":291104459,"uuid":"959088385","full_name":"Desp0o/IzziSession","owner":"Desp0o","description":"izziSession is a simple manager for secure token storage, validation, and seamless authentication handling.","archived":false,"fork":false,"pushed_at":"2025-04-27T11:11:11.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-20T17:54:28.784Z","etag":null,"topics":["api","apple","auth","authentication","authentication-middleware","authorization","ios","jwt","session","swift","token"],"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/Desp0o.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-02T08:48:49.000Z","updated_at":"2025-04-27T11:11:14.000Z","dependencies_parsed_at":"2025-05-02T12:56:26.648Z","dependency_job_id":"166bb56c-e1e3-4d62-9351-6e0b9cca5aa9","html_url":"https://github.com/Desp0o/IzziSession","commit_stats":null,"previous_names":["desp0o/izzisession"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Desp0o/IzziSession","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Desp0o%2FIzziSession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Desp0o%2FIzziSession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Desp0o%2FIzziSession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Desp0o%2FIzziSession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Desp0o","download_url":"https://codeload.github.com/Desp0o/IzziSession/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Desp0o%2FIzziSession/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263828727,"owners_count":23516791,"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":["api","apple","auth","authentication","authentication-middleware","authorization","ios","jwt","session","swift","token"],"created_at":"2025-05-18T12:10:28.734Z","updated_at":"2025-07-06T00:09:05.372Z","avatar_url":"https://github.com/Desp0o.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# izziSession\nIf your projects require user authentication and token management—handling token validation, authentication state, and secure storage—izziSession simplifies the process. It automates token storage, expiration checks, and refreshes tokens when needed, not just on app launch but also during authorized requests, ensuring seamless authentication with less effort.\n\n![Static Badge](https://img.shields.io/badge/Swit-6.0-orange) ![Static Badge](https://img.shields.io/badge/iOS-16.6%2B-white) ![Static Badge](https://img.shields.io/badge/Version%20-%201.0.0-skyblue) ![Static Badge](https://img.shields.io/badge/LICENSE-MIT-yellow) ![Static Badge](https://img.shields.io/badge/SPM-SUCCESS-green)\n\n## Features 🚀\n- Save Tokens in Keychain.\n- Retrieve Tokens from Keychain.\n- Delete Tokens from Keychain.\n- Easily Verify Token Validity: Check if the token is still valid with a simple method.\n- Default Token Models or Custom Codable Models.\n\n---------\n\n## Default Keys for Keychain 🔑\n| Parameter        | Key                   \n| :-------------- | :-------------------- |\n| `accessTokenKey`  | `izzi.session.accessToken`|\n| `refreshTokenKey` | `izzi.session.refreshToken`|\n\n---------\n\n## Configuration ⚙️\n| Parameter              | Key                                      | Description                                    | Default Value                               |\n| :--------------------- | :--------------------------------------- | :--------------------------------------------- | :------------------------------------------ |\n| `apiEndpoint`          | `string`                                 | **Required**. API endpoint.                   | N/A                                        |\n| `customRequestBuilder` | `((String) -\u003e RequestModel)`             | **Optional**. A closure that builds a custom request model using the `refreshToken`. | `DefaultRefreshRequestModel`               |\n| `tokenExtractor`       | `((ResponseModel) -\u003e String)`            | **Required**. A closure that extracts the token (e.g., `accessToken`) from the API response. | `DefaultTokenResponseModel`                |\n\n---------\n\n## Usage Guide 📖\n\nFirst, inject izziSessionManager into your project\n\n```swift\nfinal class MyProject {\n  private let izziSession: IzziSessionManager  \n\n  init(izziSession: IzziSessionManager = IzziSessionManager()) {\n    self.izziSession = izziSession\n  }\n}\n```\nThen, save the returned tokens from the response in Keychain for future use\n\n```swift\ndo {\n    let response: MyResponseModel = // API call to log in the user  \n    try izziSession.saveTokensToKeychain(accessToken: response.access, refreshToken: response.refresh)\n} catch {\n    print(error)\n}\n```\n-------\n### Check validity with default response and request models\n\nAfter successfully logging in and securely saving the tokens, on the app’s next launch, we can check token validity in RouterManager (or anywhere else) to decide where to navigate the user.\n\nYou can do this with a single line of code:\n\n```swift\nlet api = \"https://test.com/check_token\"\n\ndo {\n    try await izziSession.verifyTokenValidity(apiEndpoint: api)\n    \n    // Navigate user to the main screen\n} catch {\n    print(error)\n    \n    // Navigate user to the login screen\n}\n```\nWith the code above, we check token validity using the default request and response models, which are structured as follows:\n\n```swift\nstruct DefaultRequestModel: Codable {\n  let refresh: String\n}\n\nstruct DefaultRsponseModel: Codable {\n  let access: String\n}\n```\nIf your API only sends and receives tokens, you can freely use these default models and simply call:  `izziSession.verifyTokenValidity(apiEndpoint: api)`\n\n-------\n### Check validity with custom response and request models\nIf your API requires additional information—such as a device ID or other parameters—along with the token, you need to send a custom request model and handle a custom response model.\n\n```swift\nstruct CustomRequestModel: Codable {\n  let refreshToken: String\n  let clientId: String\n}\n\nstruct CustomResponseModel: Codable {\n  let accessToken: String\n  let deviceId: String\n  let appVersion: String\n}\n\n-------\n\nlet api = \"https://test.com/check_token\"\n\ndo {\n    try await izziSession.verifyTokenValidity(\n      apiEndpoint: api,\n      customRequestBuilder: { refreshToken in\n        CustomRequestModel(refreshToken: refreshToken, clientId: \"client123\") // Custom request model\n      },\n      tokenExtractor: { (response:CustomResponseModel) in // Custom response model\n        response.accessToken\n      }\n    )\n        \n    // your code to forward user in main screen\n} catch {\n    print(error)\n\n    // forward user in login screen\n}\n```\n----------\n\n## Delete Tokens from Keychain 🗑️\nTo log out a user, you must also delete the tokens stored in the keychain. Use the following izziSession function:\n\n```swift\nfunc logOut() {\n  do {\n    try izziSession.deleteTokensFromKeychain()\n      \n    // Your logout logic\n  } catch {\n    print(\"Error during logout: \\(error)\")\n  }\n}\n```\n-------\n## 🟢 With the verifyTokenValidity function, it’s also possible to check token validity or obtain a new token during authorized API calls. 🔄 🟢\n\n\n## Other Functions 🔧\nAdditionally, if needed, you can use the following functions:\n```swift\ntry izziSession.getAccessToken() // Retrieve only the access token  \ntry izziSession.getRefreshToken() // Retrieve only the refresh token  \ntry izziSession.saveOnlyAccessToken(token: \"testToken\") // Save only the access token  \ntry izziSession.saveOnlyRefreshToken(token: \"testToken\") // Save only the refresh token  \n```\n----\n## Installation via Swift Package Manager 🖥️\n- Open your project.\n- Go to File → Add Package Dependencies.\n- Enter URL: https://github.com/Desp0o/izziSession.git\n- Click Add Package.\n\n## Contact 📬\n\n- Email: tornike.despotashvili@gmail.com\n- LinkedIn: https://www.linkedin.com/in/tornike-despotashvili-250150219/\n- github: https://github.com/Desp0o\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdesp0o%2Fizzisession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdesp0o%2Fizzisession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdesp0o%2Fizzisession/lists"}