middlewares

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package middlewares provides the following Gin middlewares:

  • auth

The authentication middleware by sending the Bearer token to `sylvia-iot-auth`.

Here is an example to wrap the auth middleware and how to get token information:

import (
	"github.com/gin-gonic/gin"
	"github.com/woofdogtw/sylvia-iot-go/sdk/middlewares"
)

func main() {
	r := gin.Default()
	r.Use(middlewares.AuthMiddleware("http://localhost:1080/auth/api/v1/auth/tokeninfo"))
	r.GET("/", func(c *gin.Context) {
		c.AbortWithStatus(204)
	})
	r.Run()
}

Index

Constants

View Source
const (
	TokenInfoKey = "FullTokenInfo"
)

Constants.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(authUri string) func(*gin.Context)

Generate the Gin authentication middleware.

Types

type FullTokenInfo

type FullTokenInfo struct {
	Token string
	Info  GetTokenInfoData
}

The information contains `GetTokenInfoData` and access token.

type GetTokenInfo

type GetTokenInfo struct {
	Data GetTokenInfoData `json:"data"`
}

The user/client information of the token.

type GetTokenInfoData

type GetTokenInfoData struct {
	UserID   string          `json:"userId"`
	Account  string          `json:"account"`
	Roles    map[string]bool `json:"roles"`
	Name     string          `json:"name"`
	ClientID string          `json:"clientId"`
	Scopes   []string        `json:"scopes"`
}

User/client information of the token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL