Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple and sophisticated session and authentication solution written in Swift

License

NotificationsYou must be signed in to change notification settings

vitormesquita/MSession

Repository files navigation

MSession is a session and authentication solution written in Swift

It is a simple and easy solution to build a security and modular app with the latest apple biometric authentication.

MSessions usesKeychain to authenticate users and save sessions (Secret Key, User). It's really flexible, easy and scalable use in your app.

Requirements

  • Xcode 10.0+
  • Swift 5.0+

Versioning

  • Swift 4.2: 0.1.6
  • Swift 5.0: 1*

Installation

You can use each solution (Session/Auth) separately but by default, these solutions are together.

Cocoapods

pod'MSession'

The subspec if you want to use App session solution

pod'MSession/Session'

The subspec if you want to use App authentication solution

pod'Mession/Auth'

Manually

If you don't use any dependency managers, you can integrate MSession in your project manually just adding the files which contain:

Session

Session module contains all classes to manage an app session.

All this module runs around theSessionManager<T: AnyObject> class. This class is in charge to deal withcreate, update, expire and logout app session. By default, SessionManager needs anAnyObject to save on session. This object will be your "user" or "client" into the application.

So basically to use this module you need to have an instance of this class or create your own.

Create a shared instante:

staticletshared=SessionManager<User>(service:"MyAppService")

If 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.

Create your own class:

import MSessionclassAppSessionManager:SessionManager<User>{staticletshared=AppSessionManager(service:"MyAppService")...}

Create your own class is the most appropriate

To create aSessionManager instance you will need to provide aservice, it is an identifier to save and restore your app session

SessionManager by default has aDataStore implementation calledSessionDataStore, this implementation is usingNSKeyedArchiver andKeychain to save the session.

If 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 implementSessionDataStoreProtocol.

import MSessionclassAppSessionDataStore:SessionDataStoreProtocol{   // implement all methods}

And pass the new DataStore to your SessionManager

import MSessionclassAppSessionManager:SessionManager<User>{staticletshared=AppSessionManager(dataStore:AppSessionDataStore())...}

OBS: If you are using default DataStore (SessionDataStore) yourUser MUST extendsNSObject & NSCoding

Auth

Auth module contains all classes to manage authentication usingBiometry (FaceID) andKeychain.AuthManager class contains all methods which you will need to ensure a secure authentication in your app.

As the Session module, you need to have an instance ofAuthManager class or create your own.

Create a shared instance:

staticletshared=AuthManager(service:"MyAppService")

Create your own class:

import MSessionclassAppAuthManager:AuthManager{staticletshared=AppAuthManager(service:"MyAppService")...}

To create anAuthManager instance you will need to provide aservice and optionally aoccupationGroup

  • service: Identifier to save and restore saved accounts and passwords.
  • occupationGroup: An access group will create items across apps.

Not specifying anoccupationGroup(access group) will create items specific to each app.

AuthManager can be separated into two sections:

  • Save accounts and passwords (Keychain)
  • Use biometric authentication (Face/Touch ID)

Save accounts and passwords

AuthManager provides some functions to interact with Keychain and to secure users accounts and passwords. These functions are:

openfunc deleteAllAccounts()openfunc getSavedAccounts()throws->[MAccount]openfunc renameAccount(_ account:String, newAccount:String)throwsopenfunc saveAccount(account:String, password:String, deleteOthers:Bool=false)throws

MAccount is a typealias to a tuple that returnaccount: String andpassword: String

Biometric authentication

AuthManager provides some functions to interact with biometric authentication usingLAContext. These functions are:

publicvarbiometryType:BiometryTypepublicvarautomaticallyBiometryAuth:Boolopenfunc biometryIsAvailable()->Boolopenfunc biometryAuthentication(reason:String, completion:@escaping((BiometryError?)->Void))

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.

Contributing

If you think that we can do the MSession more powerful please contribute to this project. And let's improve it to help other developers.

Create a pull request or let's talk about something in issues. Thanks a lot.

Author

Vitor Mesquita,vitor.mesquita09@gmail.com

License

MSession is available under the MIT license. See the LICENSE file for more info.

About

A simple and sophisticated session and authentication solution written in Swift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp