dmao-jwt-api 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccd3141090539748b86943ccb8224a0768173b27
4
+ data.tar.gz: b202051d99a17900faec12d7e190a61a1de94eca
5
+ SHA512:
6
+ metadata.gz: 2baf81b1d2ac3597046be690f8b08225a08d2bc682658a01dffab7d63f5ebed295cd2e2779f9bc9f3ec341e6a437d740e71002d84aa85fd7a2dddbdcf82d1be9
7
+ data.tar.gz: 3f1f5ecb3981f2561776562a9c01abda567064c7156d9b9956fdbc2fe70e207f7182011a8e76bbac7aa83169bb2f8b0e6403033afeeaa289e24740c4b9392ccf
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .rbenv-gemsets
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in JWT-Service-API.gemspec
4
+ gemspec
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dmao/jwt/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dmao-jwt-api"
8
+ spec.version = DMAO::JWT::API::VERSION
9
+ spec.authors = ["Stephen Robinson"]
10
+ spec.email = ["library.dit@lancaster.ac.uk"]
11
+
12
+ spec.summary = %q{Ruby wrapper around DMAO JWT Service API}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/lulibrary/DMAO-JWT-API-rb"
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_dependency "rest-client"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.13"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency "mocha", "~> 1.1"
39
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
40
+ spec.add_development_dependency "vcr", "~> 3.0.3"
41
+ spec.add_development_dependency "webmock", "~> 2.1"
42
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Lancaster University Library
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # JWT::Service::API
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/JWT/Service/API`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'JWT-Service-API'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install JWT-Service-API
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/JWT-Service-API.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "JWT/Service/API"
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
data/bin/setup ADDED
@@ -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,24 @@
1
+ require 'rest-client'
2
+ require 'dmao/jwt/api/errors/invalid_api_base_url'
3
+ require 'dmao/jwt/api/errors/invalid_api_token'
4
+
5
+ module DMAO
6
+ module JWT
7
+ module API
8
+
9
+ class Base
10
+
11
+ def self.api
12
+
13
+ raise DMAO::JWT::API::Errors::InvalidApiBaseUrl.new if DMAO::JWT::API.base_url.nil? || DMAO::JWT::API.base_url.empty?
14
+ raise DMAO::JWT::API::Errors::InvalidApiToken.new if DMAO::JWT::API.api_token.nil? || DMAO::JWT::API.api_token.empty?
15
+
16
+ RestClient::Resource.new(DMAO::JWT::API.base_url, headers: { content_type: :json, authorization: "Bearer #{DMAO::JWT::API.api_token}" })
17
+
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+
5
+ module Configuration
6
+
7
+ attr_accessor :base_url, :api_token
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+ module Errors
5
+
6
+ class InvalidApiBaseUrl < StandardError
7
+
8
+ def initialize(msg="Api base url is invalid, please check that DMAO::JWT::API.configure has been called.")
9
+
10
+ super(msg)
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+ module Errors
5
+
6
+ class InvalidApiToken < StandardError
7
+
8
+ def initialize(msg="Api token is invalid, please check that DMAO::JWT::API.configure has been called.")
9
+
10
+ super(msg)
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+ module Errors
5
+
6
+ class InvalidJWTIssuer < StandardError
7
+
8
+ def initialize(msg="JWT Issuer not found at JWT Service")
9
+ super(msg)
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+ module Errors
5
+
6
+ class UnableToIssueToken < StandardError
7
+
8
+ def initialize()
9
+ super
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,49 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ require 'dmao/jwt/api/base'
4
+ require 'dmao/jwt/api/errors/invalid_jwt_issuer'
5
+ require 'dmao/jwt/api/errors/unable_to_issue_token'
6
+
7
+ module DMAO
8
+ module JWT
9
+ module API
10
+
11
+ class TokenIssuer
12
+
13
+ def initialize issuer_name
14
+ @issuer_name = issuer_name
15
+ end
16
+
17
+ def request_token subject, institution_id, roles
18
+
19
+ if @issuer_name.nil? || @issuer_name.empty?
20
+ raise DMAO::JWT::API::Errors::InvalidJWTIssuer.new("JWT Issuer not set for token generator")
21
+ end
22
+
23
+ custom_claims = {
24
+ institution_id: institution_id,
25
+ roles: roles
26
+ }
27
+
28
+ request_attributes = {
29
+ subject: subject,
30
+ custom_claims: custom_claims
31
+ }
32
+
33
+ begin
34
+ response = DMAO::JWT::API::Base.api["#{@issuer_name}/tokens"].post request_attributes.to_json
35
+ rescue RestClient::NotFound
36
+ raise DMAO::JWT::API::Errors::InvalidJWTIssuer
37
+ rescue RestClient::UnprocessableEntity, RestClient::InternalServerError
38
+ raise DMAO::JWT::API::Errors::UnableToIssueToken
39
+ end
40
+
41
+ JSON.parse(response.body)["token"]
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ module DMAO
2
+ module JWT
3
+ module API
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ require 'dmao/jwt/api/version'
2
+ require 'dmao/jwt/api/configuration'
3
+ require 'dmao/jwt/api/base'
4
+ require 'dmao/jwt/api/token_issuer'
5
+
6
+ module DMAO
7
+ module JWT
8
+ module API
9
+
10
+ class << self
11
+ include Configuration
12
+ end
13
+
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmao-jwt-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Robinson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.1'
125
+ description: ''
126
+ email:
127
+ - library.dit@lancaster.ac.uk
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - JWT-Service-API.gemspec
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/dmao/jwt/api/base.rb
142
+ - lib/dmao/jwt/api/configuration.rb
143
+ - lib/dmao/jwt/api/errors/invalid_api_base_url.rb
144
+ - lib/dmao/jwt/api/errors/invalid_api_token.rb
145
+ - lib/dmao/jwt/api/errors/invalid_jwt_issuer.rb
146
+ - lib/dmao/jwt/api/errors/unable_to_issue_token.rb
147
+ - lib/dmao/jwt/api/token_issuer.rb
148
+ - lib/dmao/jwt/api/version.rb
149
+ - lib/dmao_jwt_api.rb
150
+ homepage: https://github.com/lulibrary/DMAO-JWT-API-rb
151
+ licenses:
152
+ - MIT
153
+ metadata:
154
+ allowed_push_host: https://rubygems.org
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.1
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Ruby wrapper around DMAO JWT Service API
175
+ test_files: []