Git Product home page Git Product logo

edgeauth-token-node's Introduction

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

npm package Build Status License

npm package

EdgeAuth-Token-Node 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-Node supports for Node.js 4.0+

Installation

To install Akamai Edge Authorization Token with npm:

$ npm install akamai-edgeauth --save

Example

const EdgeAuth = require('akamai-edgeauth')
const http = require('http') // Module for the test


var EA_HOSTNAME = 'edgeauth.akamaized.net'
var EA_ENCRYPTION_KEY = 'YourEncryptionKey' 
var DURATION = 500 // seconds


// Function just for the simple test
function makeRequest(options, callback) {
    var request = http.request(options, (res) => {
        callback(res)
    })
    request.on('error', (err) => {
        callback(err)
    })
    request.end()
}
  • EA_ENCRYPTION_KEY must be hexadecimal digit string with even-length.
  • Don't expose EA_ENCRYPTION_KEY on the public repository.

URL parameter option

// [EXAMPLE 1] Cookie
var ea = new EdgeAuth({
    key: EA_ENCRYPTION_KEY,
    windowSeconds: DURATION,
    escapeEarly: true
})
var token = ea.generateURLToken("/akamai/edgeauth")
var options = {
    hostname: EA_HOSTNAME,
    path: '/akamai/edgeauth',
    'Cookie': `${ea.options.tokenName}=${token}`
}
makeRequest(options, function(res) {
    console.log(res.statusCode) // If pass, it won't response 403 code.
})

// [EXAMPLE 2] Query string
token = ea.generateURLToken("/akamai/edgeauth")
options = {
    hostname: EA_HOSTNAME,
    path: `/akamai/edgeauth?${ea.options.tokenName}=${token}`
}
makeRequest(options, function(res) {
    console.log(res.statusCode)
})
  • 'Escape token input' option in the Property Manager corresponds to 'escapeEarly' in the code.
    Escape token input (on) == escapeEarly (true)
    Escape token input (off) == escapeEarly (false)

  • In [Example 2] for Query String, it's only okay for 'Ignore query string' option (on).

  • If you want to 'Ignore query string' option (off) using query string as your token, Please contact your Akamai representative.

ACL(Access Control List) parameter option

// [EXAMPLE 1] Header using *
var ea = new EdgeAuth({
    key: EA_ENCRYPTION_KEY,
    windowSeconds: DURATION,
    escapeEarly: false
})
var token = ea.generateURLToken("/akamai/edgeauth/*")
var options = {
    hostname: EA_HOSTNAME,
    path: "/akamai/edgeauth/something",
    headers: {[ea.options.tokenName]: token}
}
makeRequest(options, function(res) {
    console.log(res.statusCode)
})


// [EXAMPLE 2] Cookie using ACL delimiter
var ea = new EdgeAuth({
    key: EA_ENCRYPTION_KEY,
    windowSeconds: DURATION,
    escapeEarly: false
})
var acl = ["/akamai/edgeauth/??", "/akamai/edgeauth/list/*"]
var token = ea.generateURLToken(acl)
var options = {
    hostname: EA_HOSTNAME,
    path: "/akamai/edgeauth/22",
    Cookie: `${ea.options.tokenName}: ${token}`
}
makeRequest(options, function(res) {
    console.log(res.statusCode)
})
  • 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 Class

class EdgeAuth {
    constructor(options) {}
}
Parameter Description
options.tokenType Select a preset. (Not Supported Yet)
options.tokenName Parameter name for the new token. [ Default: __token__ ]
options.key Secret required to generate the token. It must be hexadecimal digit string with even-length.
options.algorithm Algorithm to use to generate the token. ('sha1', 'sha256', or 'md5') [ Default: 'sha256' ]
options.salt Additional data validated by the token but NOT included in the token body. (It will be deprecated)
options.startTime What is the start time? (Use string 'now' for the current time)
options.endTime When does this token expire? endTime overrides windowSeconds
options.windowSeconds How long is this token valid for?
options.fieldDelimiter Character used to delimit token body fields. [ Default: ~ ]
options.aclDelimiter Character used to delimit acl. [ Default: ! ]
options.escapeEarly Causes strings to be url encoded before being used.
options.verbose Print all parameters.

EdgeAuth's Method

generateURLToken(url) {}
generateACLToken(acl) {}

// both return the authorization token string.
Parameter Description
url Single URL path (String)
acl Access Control List can use the wildcard(*, ?). It can be String (single path) or Array (multi paths)

Others

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

Command

You can use the command with cms-edgeauth.js in your terminal with commander to generate the token.

$ npm install commander --save
$ node cms-edgeauth.js --key YourEncryptionKey --window 5000 --url /hello/world --escape_early

Use -h or --help option for the detail.

edgeauth-token-node's People

Contributors

aka-mark avatar astinchoi avatar goodjoon avatar skearney-akamai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

edgeauth-token-node's Issues

[Example 2] missing /* or /filename, as edgeauth alone does not work

to implement a Lambda function to generate tokens.

This particular info is wrong // [EXAMPLE 2] Query string
token = ea.generateURLToken("/akamai/edgeauth")

Should be either for example
// [EXAMPLE 2] Query string
token = ea.generateURLToken("/akamai/edgeauth/*")
or
// [EXAMPLE 2] Query string
token = ea.generateURLToken("/akamai/edgeauth/file.zip")

Please review Test and update the documentation accordingly.

edgeauth-cms.js compatibility with commander v7+

Hi,

The script is not compatible with commander 7+ versions (now it is on v8.0.0 as LTS)
You need to user commander 6.1.0 in order to use cms-edgeauth.js as it writed or add the method opts() to the "program." object to "program.opts()." to retreieve command variables...

var ea = new EdgeAuth({
tokenType: program.opts().token_type,
tokenName: program.opts().token_name,
key: program.opts().key,
algorithm: program.opts().algo,
salt: program.opts().salt,
startTime: program.opts().start_time,
endTime: program.opts().end_time,
windowSeconds: program.opts().window,
fieldDelimiter: program.opts().field_delimiter,
aclDelimiter: program.opts().acl_delimiter,
escapeEarly: program.opts().escape_early,
verbose: program.opts().verbose,
url: program.opts().url,
acl: program.opts().acl,
ip: program.opts().ip,
payload: program.opts().payload,
sessionId: program.opts().session_id
})

var token
if (program.acl) {
token = ea.generateACLToken(program.opts().acl)
} else { // program.url
token = ea.generateURLToken(program.opts().url)
}

key must be provided to generate a token

I am getting Key must be provided error to generate token but i am already providing key in the command i am using below command
./cms-edgeauth.js --key MYKEY --window 5000 --url /Renditions/20230613/1686641817553_parija_1686638343897_t_CUSTOM_CODEC_TS/hls/master.m3u8 --escape_early

were i am doing wrong please help

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.