github.com/IBM-Swift/Kitura-Session

A pluggable framework for managing user sessions in a Swift server using Kitura


License
Apache-2.0

Documentation

Kitura-Session

A pluggable framework for managing user sessions in a Swift server using Kitura

Build Status - Master Mac OS X Linux Apache 2

Summary

A pluggable framework for managing user sessions in a Swift server using Kitura

Table of Contents

Swift version

The latest version of Kitura-Session works with the DEVELOPMENT-SNAPSHOT-2016-06-20-a version of the Swift binaries. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

API

In order to use Session middleware, an instance of Session has to created:

public init(secret: String, cookie: [CookieParameter]?=nil, store: Store?=nil)

Where:

  • secret is a String to be used for session encoding.
  • cookie is a list of options for session's cookies. The options are (specified in CookieParameter enumeration): name - cookie's name, defaults to "kitura-session-id", path - cookie's Path attribute defaults to "/", secure - cookie's Secure attribute, false by default, and maxAge - an NSTimeInterval with cookie's expiration time in seconds, defaults to -1.0, i.e., no expiration.
  • store is an instance of a plugin for session backing store that implements Store protocol. If not set, InMemoryStore is used.

    The last two parameters are optional.

Example

This is an example of Session middleware with KituraSessionRedis plugin:

import KituraSession
import KituraSessionRedis

let redisStore = RedisStore(redisHost: host, redisPort: port)
let session = Session(secret: "Some secret", store: redisStore)
router.all(middleware: session)

First an instance of RedisStore is created (see KituraSessionRedis for more information), then an instance of Session with the store as parameter is created, and finally it is connected to the desired path.

Plugins

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.