Skip to content

A plugin for the Kitura-Credentials framework that authenticates using the Sign in with Slack

License

Notifications You must be signed in to change notification settings

lluisgerard/Kitura-CredentialsSlack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kitura-CredentialsSlack

A plugin for the Credentials framework that authenticates using Slack.

Mac OS X Linux Apache 2

Summary

A very rough plugin for Kitura-Credentials framework that authenticates using the Sign in with Slack button. I adapted the code from Kitura-CredentialsFacebook.

Table of Contents

Swift version

The latest version of Kitura-CredentialsSlack works with the DEVELOPMENT-SNAPSHOT-2016-05-03-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.

Example

A complete sample for other credentials can be found in Kitura-Credentials-Sample. I plan to add the Slack example but I totally recommend trying to build and play with that project first before using this module.

I was able to use it inside the complete sample by adding the next line in the dependencies before swift build and swift build -X (this last one only needed if you want to create an Xcode project):

.Package(url: "https://github.com/lluisgerard/Kitura-CredentialsSlack.git", majorVersion: 0, minor: 1),

To use it, first create an instance of CredentialsSlack plugin and register it with Credentials framework:

import Credentials
import CredentialsSlack

let credentials = Credentials()
let slackCredentials = CredentialsSlack(clientId: slackClientId, clientSecret: slackClientSecret, callbackUrl: slackCallbackUrl)
credentials.register(plugin: slackCredentials)

Where:

  • slackClientId is the App ID of your Slack app
  • slackClientSecret is the App Secret of your Slack app

Note: The callbackUrl parameter above is used to tell the Slack web login page where the user's browser should be redirected when the login is successful. It should be a URL handled by the server you are writing.

Connect credentials middleware to requests to /private:

router.all("/private", middleware: credentials)
router.get("/private/data", handler:
    { request, response, next in
        ...  
        next()
})

And call authenticate to login with Slack and to handle the redirect (callback) from the Slack login web page after a successful login:

// SLACK
router.get("/login/slack",
           handler: credentials.authenticate(credentialsType: slackCredentials.name))
router.get("/login/slack/callback",
           handler: credentials.authenticate(credentialsType: slackCredentials.name, failureRedirect: "/login"))

License

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

About

A plugin for the Kitura-Credentials framework that authenticates using the Sign in with Slack

Resources

License

Stars

Watchers

Forks

Packages

No packages published