akamai-edge_auth 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4eb6c5e2bea17ce0a682ffaf0a215f7db4bba186
4
+ data.tar.gz: 10584aeb37a3ba4cae5038147b3c5f78f5fd7a12
5
+ SHA512:
6
+ metadata.gz: e598f0b103f69755b8e00af8e617c016d9d447912e85104f4b8cd19b8433d31b8254da15afbc57a0c76effa8f7e1d9a733c98330a657e4a09d1ea24af461e093
7
+ data.tar.gz: 17547a958f84bb57bf70ea2f8e5e879e40e6b58d6bfd16605de257b11b34d4116224ef3b8ec222d3c45420e33dd345d1aaeff1d49a6c12b640e9468eb6fbd177
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in edge_auth.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2017 Akamai Technologies http://developer.akamai.com.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ Copyright 2017 Akamai Technologies http://developer.akamai.com.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,94 @@
1
+ # EdgeAuth (Akamai Authorization Token)
2
+
3
+ this gem is authorization token generator for Akamai, you can configure your property at [https://control.akamai.com]
4
+ inspired by [Akamai-AuthToken-Ruby](https://github.com/AstinCHOI/Akamai-AuthToken-Ruby)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'edge_auth'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install edge_auth
21
+
22
+ ## Usage
23
+
24
+ ### Basic Usage
25
+
26
+ ```Ruby
27
+ edge_auth = Akamai::EdgeAuth.new(key: "yourkeyhere")
28
+ token = edge_auth.generate_token(start_time: "now", window_seconds: 30, acl: "/path/whatever")
29
+ ```
30
+
31
+ Your token should look like this by very default options :
32
+
33
+ ```
34
+ hdnts=st=1508777863~exp=1508777893~acl=/path/whatever~hmac=fded4c1133a50942a36cc16a9a94d68e8573d10d144d03860a7c3a3734d13dff
35
+ ```
36
+
37
+ ### Initialize
38
+
39
+ | Parameter | Description |
40
+ |-----------|-------------|
41
+ | token_type| Token type cookies or URL. [ Default: URL] |
42
+ | token_name | Parameter name for the new token. [ Default: hdnts ] |
43
+ | key | Secret required to generate the token. It must be hexadecimal digit string with even-length. |
44
+ | algorithm | Algorithm to use to generate the token. (sha1, sha256, or md5) [ Default:sha256 ] |
45
+ | field_delimiter | Character used to delimit token body fields. [ Default: ~ ] |
46
+ | acl_delimiter | Character used to delimit acl. [ Default: ! ] |
47
+
48
+ ### Generate Token
49
+
50
+ | Parameter | Description |
51
+ |-----------|-------------|
52
+ | start_time | What is the start time? (Use string 'now' for the current time) |
53
+ | end_time | When does this token expire? 'end_time' |
54
+ | window_seconds | How long is this token valid for? overrides 'end_time' |
55
+ | acl | Generate token for Access Control List [ Example: "/live/*" it will allow all stream under /live/ path ] |
56
+ | url | Generate token for url |
57
+ | escape_early | Causes strings to be 'url' encoded before being used. |
58
+ | ip | IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used) |
59
+ | payload | Additional text added to the calculated digest. |
60
+ | session_id | The session identifier for single use tokens or other advanced cases. |
61
+ | salt | Additional data validated by the token but NOT included in the token body. (It will be deprecated) |
62
+
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( https://github.com/sukorenomw/akamai-edgeauth/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sukorenomw/akamai-edgeauth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
79
+
80
+ ## License
81
+
82
+ Copyright 2017 Akamai Technologies http://developer.akamai.com.
83
+
84
+ Licensed under the Apache License, Version 2.0 (the "License");
85
+ you may not use this file except in compliance with the License.
86
+ You may obtain a copy of the License at
87
+
88
+ http://www.apache.org/licenses/LICENSE-2.0
89
+
90
+ Unless required by applicable law or agreed to in writing, software
91
+ distributed under the License is distributed on an "AS IS" BASIS,
92
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93
+ See the License for the specific language governing permissions and
94
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "akamai/edge_auth"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "akamai/edge_auth/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "akamai-edge_auth"
8
+ spec.version = Akamai::EdgeAuth::VERSION
9
+ spec.authors = ["Sukoreno Mukti"]
10
+ spec.email = ["sukorenomw@gmail.com"]
11
+
12
+ spec.summary = %q{Akamai EdgeAuth token generator}
13
+ spec.description = %q{Akamai EdgeAuth token generator for TokenAuth setting in Media Live Streaming Packaging or Segmented Media Protection}
14
+ spec.homepage = "https://github.com/sukorenomw/akamai_edge_auth"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency 'timecop', '~> 0'
37
+ end
@@ -0,0 +1,90 @@
1
+ require "akamai/edge_auth/version"
2
+ require "openssl"
3
+
4
+ module Akamai
5
+ class EdgeAuth
6
+ attr_accessor :key, :token_type, :token_name,
7
+ :algorithm, :field_delimiter, :acl_delimiter
8
+
9
+ ALLOWED_ALGORITHM = ['sha256', 'sha1', 'md5']
10
+
11
+ def initialize(key: nil, token_type: "URL", token_name: "hdnts",
12
+ algorithm: "sha256", field_delimiter: "~", acl_delimiter: "!")
13
+
14
+ raise EdgeAuthError, "no key provided" if key.nil? || key.length < 1
15
+ raise EdgeAuthError, "algorithm must be one of 'sha256', 'sha1' or 'md5'" unless ALLOWED_ALGORITHM.include? algorithm
16
+
17
+ @key = key
18
+ @token_type = token_type
19
+ @token_name = token_name
20
+ @algorithm = algorithm
21
+ @field_delimiter = field_delimiter
22
+ @acl_delimiter = acl_delimiter
23
+ end
24
+
25
+ def generate_token(start_time: "now", end_time: nil, window_seconds: nil,
26
+ acl: nil, url: nil)
27
+ raise EdgeAuthError, "no end_time or window_seconds is provided" if end_time.nil? && window_seconds.nil?
28
+ raise EdgeAuthError, "you must provide an ACL or a URL." if (acl.nil? && url.nil?) || (acl && url)
29
+
30
+ if start_time.to_s.downcase == "now"
31
+ start_time = Time.now.getgm.to_i
32
+ else
33
+ begin
34
+ start_time = 0 if start_time < 0
35
+ rescue
36
+ raise EdgeAuthError, "start_time must be UNIX timestamps or 'now'"
37
+ end
38
+ end
39
+
40
+ if end_time
41
+ begin
42
+ end_time = 0 if end_time < 0
43
+ rescue
44
+ raise EdgeAuthError, "end_time must be UNIX timestamps."
45
+ end
46
+ end
47
+
48
+ if window_seconds
49
+ begin
50
+ end_time = start_time + window_seconds
51
+ rescue
52
+ raise EdgeAuthError, "window_seconds must be numeric."
53
+ end
54
+ end
55
+
56
+ if end_time <= start_time
57
+ raise EdgeAuthError, "token will have already expired."
58
+ end
59
+
60
+ new_token = Array.new
61
+
62
+ new_token.push "st=#{start_time}"
63
+ new_token.push "exp=#{end_time}"
64
+
65
+ new_token.push "acl=#{acl}" unless acl.nil?
66
+ new_token.push "url=#{url}" unless url.nil?
67
+
68
+ hash_code = new_token.clone
69
+
70
+ bin_key = Array(key.gsub(/\s/,'')).pack("H*")
71
+ digest = OpenSSL::Digest.new(algorithm)
72
+ token_hmac = OpenSSL::HMAC.new(bin_key, digest)
73
+ token_hmac.update(hash_code.join(field_delimiter))
74
+
75
+ new_token.push "hmac=#{token_hmac}"
76
+
77
+ "#{@token_name}=#{new_token.join(@field_delimiter)}"
78
+ end
79
+
80
+ def escape_early(string)
81
+ CGI::escape(string).gsub(/(%..)/) {$1.downcase}
82
+ end
83
+ end
84
+
85
+ class EdgeAuthError < StandardError
86
+ def initialize(msg = "StandardError")
87
+ super
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ module Akamai
2
+ class EdgeAuth
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akamai-edge_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sukoreno Mukti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Akamai EdgeAuth token generator for TokenAuth setting in Media Live Streaming
70
+ Packaging or Segmented Media Protection
71
+ email:
72
+ - sukorenomw@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - edge_auth.gemspec
88
+ - lib/akamai/edge_auth.rb
89
+ - lib/akamai/edge_auth/version.rb
90
+ homepage: https://github.com/sukorenomw/akamai_edge_auth
91
+ licenses:
92
+ - MIT
93
+ metadata:
94
+ allowed_push_host: https://rubygems.org
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Akamai EdgeAuth token generator
115
+ test_files: []