Categorygithub.com/mobilerider/edgeauth-token-golang
repositorypackage
0.0.0-20190711201436-99a4f4745353
Repository: https://github.com/mobilerider/edgeauth-token-golang.git
Documentation: pkg.go.dev

# README

EdgeAuth-Token-Golang: Akamai Edge Authorization Token for Golang

EdgeAuth-Token-Golang is Akamai Edge Authorization Token in the HTTP Cookie, Query String and Header for a client. You can configure it in the Property Manager at https://control.akamai.com. It's the behaviors which is Auth Token 2.0 Verification and Segmented Media Protection.

EdgeAuth-Token-Golang supports for Golang 1.x

Installation

To install Akamai Edge Authorization Token with dep:

$ dep ensure -add github.com/mobilerider/EdgeAuth-Token-Golang

Examples

ACL (Access Control List) parameter option

package main

import "github.com/mobilerider/EdgeAuth-Token-Golang/edgeauth"

func main {
    acl := "/s/c/m/f/5/9/2/f5929e909d4/*"
    key := "52a152a152a152a152a152a152a1"

    config := &edgeauth.Config{
		Algo:           crypto.SHA256,
		Key:            sampleKey,
		DurationWindow: 300 * time.Second,
	}

	client := edgeauth.NewClient(config)

    token, err := client.GenerateToken(acl, false)
    
    if err != nil {
		// Handle error
    }

    // Use generated token

    // token would be in the form of:
    // exp=1562609231~acl=/s/c/m/f/5/9/2/f5929e909d4/*~hmac=7a6bd5d5abdad74bda765b4da67b7ad54b6a4d6ba54d67b4ad76b4

    // You will probably use that token as a value of a cookie 
    // or query string parameter, the name of the parameter is 
    // configured via PM
}

  • ACL can use the wildcard(*, ?) in the path.
  • Don't use '!' in your path because it's ACL Delimiter
  • Use 'escapeEarly=false' as default setting but it doesn't matter turning on/off 'Escape token input' option in the Property Manager

Usage

EdgeAuth Config Class

type Config struct {
	Algo           crypto.Hash
	Key            string
	Salt           string
	FieldDelimiter string
	ACLDelimiter   string
	StartTime      time.Time
	EndTime        time.Time
	DurationWindow time.Duration
	IP             string
	SessionID      string
	Payload        string
	Verbose        bool
}
ParameterDescription
KeySecret required to generate the token. It must be hexadecimal digit string with even-length.
AlgoAlgorithm to use to generate the token. ('sha1', 'sha256', or 'md5') [ Default: 'sha256' ]
SaltAdditional data validated by the token but NOT included in the token body. (It will be deprecated)
StartTimeWhat is the start time? (Use string 'now' for the current time)
EndTimeWhen does this token expire? endTime overrides windowSeconds
DurationWindowHow long is this token valid for?
FieldDelimiterCharacter used to delimit token body fields. [ Default: ~ ]
AclDelimiterCharacter used to delimit acl. [ Default: ! ]
EscapeEarlyNot implemented yet.
VerboseNot implemented yet.

EdgeAuth's Method

client.GenerateToken(value, isUrl) {}
ParameterDescription
valueSingle URL path or Access Control List (String)
isUrlWether passed value is a url or not (Boolean)

Others

If you use the Segmented Media Protection behavior in AMD(Adaptive Media Delivery) Product, tokenName(options.tokenName) should be 'hdnts'.

TODOs

  1. Implement EscapeEarly option
  2. Implement Verbose option

Inspired in https://github.com/akamai/EdgeAuth-Token-Node

Important!!: This is NOT an official library from Akamai Technologies.