Git Product home page Git Product logo

stream-chat-vapor-swift's Introduction

StreamChat Vapor Swift Backend

This library contains the code to integrate client applications with Stream's backend using Vapor Swift. It also contains an example application demonstrating how to integrate the library with a Vapor applications.

Integrating the libray

Add the library as a dependency to your Package.swift:

dependencies: [
    // ...
    .package(name: "StreamChat", url: "https://github.com/GetStream/stream-chat-vapor-swift.git", from: "0.1.0"),
],

Then add the the dependency to your application, e.g.:

.target(
    name: "App",
    dependencies: [
        .product(name: "StreamSDKVapor", package: "StreamChat"),
        // ...
    ],
    // ...

Configuration

The Stream library requires your Stream access key and access secret to work. Configure the libray as so:

// Get the keys, for example from environment variables
guard let streamAccessKey = Environment.get("STREAM_ACCESS_KEY"), let streamAccessSecret = Environment.get("STREAM_ACCESS_SECRET") else {
    app.logger.critical("STREAM keys not set")
    fatalError("STREAM keys not set")
}

let streamConfig = StreamConfiguration(accessKey: streamAccessKey, accessSecret: streamAccessSecret)
app.stream.use(streamConfig)

Generating a JWT

To generate a JWT to use with Stream's backend you need the user ID. You can then call the Stream library to generate the token:

let streamToken = try req.stream.createToken(name: userID)

You can pass an optional date for the token to expire at as well:

let streamToken = try req.stream.createToken(name: userID, expiresAt: Date().addingTimeInterval(3600))

Running the sample application

To get started you need to do a couple things:

  • Install Docker Desktop.
  • Run ./scripts/localDockerDB.swift start
  • open Package.swift
  • Set working dir of scheme in Xcode to root of project.
  • Run project

The application allows users to register traditionally by sending a POST request to /auth/register and also using Sign In With Apple.

When registering or logging in the Vapor app returns both an API key for interacting with the API as the authenticated user and also a JWT for use with Stream's backend.

More example code

See these supporting repositories to see how integrating this libary would look in your codebase:

Blog article

We also have a blog article describing what is in this repository and how to get started.

stream-chat-vapor-swift's People

Contributors

0xtim avatar finestructure avatar jeroenleenarts avatar marco-ulge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  avatar  avatar  avatar

Forkers

finestructure

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.