{"id":21102117,"url":"https://github.com/vitormesquita/msession","last_synced_at":"2025-07-25T17:33:16.281Z","repository":{"id":62447133,"uuid":"139623100","full_name":"vitormesquita/MSession","owner":"vitormesquita","description":"A simple and sophisticated session and authentication solution written in Swift","archived":false,"fork":false,"pushed_at":"2019-05-07T19:19:54.000Z","size":71,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T08:08:38.029Z","etag":null,"topics":["apple","authentication","faceid","faceid-authentication","ios","keychain","secur","security","session","swift","swift-library"],"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/vitormesquita.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":"2018-07-03T18:25:56.000Z","updated_at":"2024-03-18T22:40:11.000Z","dependencies_parsed_at":"2022-11-01T23:05:22.790Z","dependency_job_id":null,"html_url":"https://github.com/vitormesquita/MSession","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/vitormesquita/MSession","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitormesquita%2FMSession","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitormesquita%2FMSession/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitormesquita%2FMSession/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitormesquita%2FMSession/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitormesquita","download_url":"https://codeload.github.com/vitormesquita/MSession/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitormesquita%2FMSession/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267040427,"owners_count":24025900,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["apple","authentication","faceid","faceid-authentication","ios","keychain","secur","security","session","swift","swift-library"],"created_at":"2024-11-19T23:54:04.331Z","updated_at":"2025-07-25T17:33:16.203Z","avatar_url":"https://github.com/vitormesquita.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MSession\n\n## MSession is a session and authentication solution written in Swift\n\n### It is a simple and easy solution to build a security and modular app with the latest apple biometric authentication.\n\nMSessions uses `Keychain` to authenticate users and save sessions (Secret Key, User). It's really flexible, easy and scalable use in your app.\n\n## Requirements\n\n- Xcode 10.0+\n- Swift 5.0+\n\n## Versioning\n\n- *Swift 4.2*: 0.1.6\n- *Swift 5.0*: 1*\n\n## Installation\n\nYou can use each solution (Session/Auth) separately but by default, these solutions are together.\n\n### Cocoapods\n\n```ruby\npod 'MSession'\n```\n\nThe subspec if you want to use App session solution\n\n```ruby\npod 'MSession/Session'\n```\n\nThe subspec if you want to use App authentication solution\n\n```ruby\npod 'Mession/Auth'\n```\n\n### Manually\n\nIf you don't use any dependency managers, you can integrate MSession in your project manually just adding the files which contain:\n\n- [MSession Classes](https://github.com/vitormesquita/MSession/tree/master/Source). \n- [Session Classes](https://github.com/vitormesquita/MSession/tree/master/Source/Session).\n- [Auth Classes](https://github.com/vitormesquita/MSession/tree/master/Source/Auth).\n\n## Session\n\nSession module contains all classes to manage an app session. \n\nAll this module runs around the `SessionManager\u003cT: AnyObject\u003e` class. This class is in charge to deal with ***create, update, expire and logout*** app session. By default, SessionManager needs an `AnyObject` to save on session. This object will be your \"user\" or \"client\" into the application.\n\nSo basically to use this module you need to have an instance of this class or create your own.\n\n**Create a shared instante:**\n\n```swift\nstatic let shared = SessionManager\u003cUser\u003e(service: \"MyAppService\")\n```\n\nIf you want to improve more things in your app session, like put an expire time or something else is more appropriate to create your own class.\n\n**Create your own class:**\n\n```swift\nimport MSession\n\nclass AppSessionManager: SessionManager\u003cUser\u003e {\n\n static let shared = AppSessionManager(service: \"MyAppService\")\n ...\n \n}\n```\n\n*Create your own class is the most appropriate*\n\nTo create a `SessionManager` instance you will need to provide a `service`, it is an identifier to save and restore your app session\n\n`SessionManager` by default has a `DataStore` implementation called `SessionDataStore`, this implementation is using `NSKeyedArchiver` and `Keychain` to save the session.\n\nIf you want to create a local store with realm or core data you can use MSession as well. You just need to create your own DataStore and implement `SessionDataStoreProtocol`.\n\n```swift\nimport MSession\n\nclass AppSessionDataStore: SessionDataStoreProtocol {\n   // implement all methods\n}\n```\n\nAnd pass the new DataStore to your SessionManager\n\n```swift\nimport MSession\n\nclass AppSessionManager: SessionManager\u003cUser\u003e {\n\n   static let shared = AppSessionManager(dataStore: AppSessionDataStore())\n   ...\n \n}\n```\n\n**OBS: If you are using default DataStore (SessionDataStore) your `User` MUST extends `NSObject \u0026 NSCoding`**\n\n## Auth\n\nAuth module contains all classes to manage authentication using `Biometry (FaceID)` and `Keychain`. `AuthManager` class contains all methods which you will need to ensure a secure authentication in your app.\n\nAs the Session module, you need to have an instance of `AuthManager` class or create your own.\n\n**Create a shared instance:**\n\n```swift\nstatic let shared = AuthManager(service: \"MyAppService\")\n\n```\n\n**Create your own class:**\n\n```swift\nimport MSession\n\nclass AppAuthManager: AuthManager {\n   \n   static let shared = AppAuthManager(service: \"MyAppService\")\n   ...\n}\n```\n\nTo create an `AuthManager` instance you will need to provide a `service` and optionally a `occupationGroup`\n\n- `service`: Identifier to save and restore saved accounts and passwords.\n- `occupationGroup`: An access group will create items across apps.\n\t\nNot specifying an `occupationGroup`(access group) will create items specific to each app.\n\n`AuthManager` can be separated into two sections:\n\n- Save accounts and passwords (Keychain)\n- Use biometric authentication (Face/Touch ID)\n\n### Save accounts and passwords \n\nAuthManager provides some functions to interact with Keychain and to secure users accounts and passwords. These functions are:\n\n```swift\nopen func deleteAllAccounts()\nopen func getSavedAccounts() throws -\u003e [MAccount]\nopen func renameAccount(_ account: String, newAccount: String) throws\nopen func saveAccount(account: String, password: String, deleteOthers: Bool = false) throws\n```\n\n`MAccount` is a typealias to a tuple that return `account: String` and `password: String`\n\n### Biometric authentication\n\nAuthManager provides some functions to interact with biometric authentication using `LAContext`. These functions are:\n\n```swift\npublic var biometryType: BiometryType\npublic var automaticallyBiometryAuth: Bool\n\nopen func biometryIsAvailable() -\u003e Bool\nopen func biometryAuthentication(reason: String, completion: @escaping ((BiometryError?) -\u003e Void))\n```\n\n`LAContext` is just available to iOS 11 or later, but you don't need to check any function to call. MSession handles it to you, but of course, some functions will return an error if you try to use it on iOS 10.\n\n## Contributing\n\t\nIf you think that we can do the MSession more powerful please contribute to this project. And let's improve it to help other developers.\n\nCreate a pull request or let's talk about something in issues. Thanks a lot.\n\n## Author\n\nVitor Mesquita, vitor.mesquita09@gmail.com\n\n## License\n\nMSession is available under the MIT license. See the LICENSE file for more info.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitormesquita%2Fmsession","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitormesquita%2Fmsession","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitormesquita%2Fmsession/lists"}