uriauth

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: MIT Imports: 7 Imported by: 0

README

uriauth

URI Auth

example

package main

import (
    "fmt"
    "time"

    "github.com/GiterLab/uriauth"
)

func main() {
    uri := "rtmp://ipc.example.com/live/test?a=123&b=456" // original uri
    key := "<input your key>"                             // private key of authorization
    exp := time.Now().Unix() + 3600                       // expiration time: 1 hour after current itme
    authURI, err := uriauth.URIAuth(uri, "0", "0", key, exp)
    if err != nil {
        fmt.Println(err)
    }
    // 签名URL结果
    fmt.Println("Auth:", authURI)
    // 对 authURI 进行校验
    fmt.Println(uriauth.URIAuthCheck(authURI, key))
    // 对 authURI 提取 path & args
    fmt.Println(uriauth.URIAuthParse(authURI))
    // 直接计算签名
    fmt.Println("Auth:", exp, uriauth.URIPathAuth("/live/test", "", "", key, exp))
}

$ go run main.go
Auth: rtmp://ipc.example.com/live/test?a=123&b=456&auth_key=1641311904-0-0-6ecce59d62eef5eab899a9be1dee4b3b
true
/live/test map[a:[123] auth_key:[1641311904-0-0-6ecce59d62eef5eab899a9be1dee4b3b] b:[456]] <nil>
Auth: 1641311904 6ecce59d62eef5eab899a9be1dee4b3b

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func URIAuth

func URIAuth(uri, rand, uid, key string, exp int64) (string, error)

URIAuth 视频URL签名 uri URL链接 rand 算法,默认为0 uid 用户ID,默认为0 key 用户签名key,不可公开,不可为空 exp 过期时间戳, 单位秒

func URIAuthCheck

func URIAuthCheck(uri, key string) bool

URIAuthCheck 验证签名串是否合法 uri URL链接 key 用户签名key,不可公开, 不可为空

func URIAuthParse

func URIAuthParse(uri string) (path string, args url.Values, err error)

URIAuthParse 从URL中提取出 path & args

func URIPathAuth added in v1.0.2

func URIPathAuth(path, rand, uid, key string, exp int64) string

URIPathAuth 直接计算PATH签名 path like: /live/test, 已 / 开头 key 用户签名key,不可公开, 不可为空

Types

This section is empty.

Jump to

Keyboard shortcuts

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