Giter VIP home page Giter VIP logo

msession's Introduction

MSession

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 uses Keychain 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 the SessionManager<T: AnyObject> 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.

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

Create a shared instante:

static let shared = 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 MSession

class AppSessionManager: SessionManager<User> {

 static let shared = AppSessionManager(service: "MyAppService")
 ...
 
}

Create your own class is the most appropriate

To create a SessionManager instance you will need to provide a service, it is an identifier to save and restore your app session

SessionManager by default has a DataStore implementation called SessionDataStore, this implementation is using NSKeyedArchiver and Keychain 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 implement SessionDataStoreProtocol.

import MSession

class AppSessionDataStore: SessionDataStoreProtocol {
   // implement all methods
}

And pass the new DataStore to your SessionManager

import MSession

class AppSessionManager: SessionManager<User> {

   static let shared = AppSessionManager(dataStore: AppSessionDataStore())
   ...
 
}

OBS: If you are using default DataStore (SessionDataStore) your User MUST extends NSObject & NSCoding

Auth

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

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

Create a shared instance:

static let shared = AuthManager(service: "MyAppService")

Create your own class:

import MSession

class AppAuthManager: AuthManager {
   
   static let shared = AppAuthManager(service: "MyAppService")
   ...
}

To create an AuthManager instance you will need to provide a service and optionally a occupationGroup

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

Not specifying an occupationGroup(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:

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

MAccount is a typealias to a tuple that return account: String and password: String

Biometric authentication

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

public var biometryType: BiometryType
public var automaticallyBiometryAuth: Bool

open func biometryIsAvailable() -> Bool
open func 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, [email protected]

License

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

msession's People

Contributors

vitorjera avatar vitormesquita avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gemicn

msession's Issues

null pointer exception

I'm trying to implement this lib on my project put i keep reciving this error pls help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.