work_auth_client 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
+ SHA256:
3
+ metadata.gz: e6bc9ab3e268219006f9a3395a2bbebfc24e7ecb8d506ae42d25fe11db2d87b0
4
+ data.tar.gz: 7aba6065db2b0129ce6bff0bfd1d8dde8cf737baa9872f8421f8abd3e5a88527
5
+ SHA512:
6
+ metadata.gz: 966dd675a08393c830d011dba8b31980e0637c54be0627e34be7a30d92b9ce7fe81aafe318df04aa6c8504fe41efc49952bc031ade078b498e17caa93369a125
7
+ data.tar.gz: c2f5ff889d003edefdb44b273e7ace4a95cda2b2586fdd1e1098b0c591ffc446501046214a727818cc2fdf07a3b92685070cc9b48cb2a21b3b7e2fd9eb30790d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in work_auth_client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # WorkAuthClient
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/work_auth_client`. 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 'work_auth_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install work_auth_client
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. 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]/work_auth_client.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "work_auth_client"
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__)
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,3 @@
1
+ module WorkAuthClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,95 @@
1
+ require 'rest-client'
2
+ require 'work_auth_client/version'
3
+
4
+ module WorkAuthClient
5
+ class Error < StandardError; end
6
+
7
+
8
+ class Client
9
+
10
+ # TODO: Figure out best way to configure host information
11
+ attr_accessor :host
12
+
13
+ # `access_token` makes a request to the auth server to generate an access
14
+ # token according to the request. Currently, the auth server only supports
15
+ # the following grant_types:
16
+ # - client_credentials
17
+ # - password
18
+ def access_token(request)
19
+ validate_host
20
+
21
+ if !request.is_a?(ClientCredentialsRequest) || !request.is_a?(PasswordRequest)
22
+ raise ArgumentError
23
+ end
24
+
25
+ RestClient.post("#{self.host}/access_token", request.as_json, {
26
+ content_type: :json,
27
+ accept: :json
28
+ })
29
+ end
30
+
31
+ # `verification` makes a call to the authorization server in order to get
32
+ # verification of the access_token provided.
33
+ def verification(request)
34
+ validate_host
35
+
36
+ if !request.is_a?(ClientCredentialsRequest) || !request.is_a?(PasswordRequest)
37
+ raise ArgumentError
38
+ end
39
+
40
+ RestClient.post("#{self.host}/access_token", request.as_json, {
41
+ content_type: :json,
42
+ accept: :json
43
+ })
44
+ end
45
+
46
+ private
47
+
48
+ def validate_host
49
+ if self.host.nil? || self.host == ''
50
+ raise RuntimeError, 'host not defined. Please set it using client.host = "http://example.com"'
51
+ end
52
+ end
53
+ end
54
+
55
+ class ClientCredentialsRequest
56
+ attr_accessor :client_id, :client_secret
57
+
58
+ def initialize(client_id:, client_secret:)
59
+ self.client_id = client_id
60
+ self.client_secret = client_secret
61
+ end
62
+
63
+ def as_json
64
+ {
65
+ client_id: client_id,
66
+ client_secret: client_secret,
67
+ grant_type: 'client_credentials',
68
+ }
69
+ end
70
+ end
71
+
72
+ class PasswordRequest
73
+ attr_accessor :client_id, :client_secret, :username, :password
74
+
75
+ def initialize(client_id:, client_secret:, username:, password:)
76
+ self.client_id = client_id
77
+ self.client_secret = client_secret
78
+ self.username = username
79
+ self.password = password
80
+ end
81
+
82
+ def as_json
83
+ {
84
+ client_id: client_id,
85
+ client_secret: client_secret,
86
+ username: username,
87
+ password: password,
88
+ grant_type: 'password',
89
+ }
90
+ end
91
+ end
92
+
93
+ class VerificationRequest
94
+ end
95
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "work_auth_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "work_auth_client"
8
+ spec.version = WorkAuthClient::VERSION
9
+ spec.authors = ["Andrew Sinner"]
10
+ spec.email = ["andrewsinner@gmail.com"]
11
+
12
+ spec.summary = "Ruby work-auth client"
13
+ spec.description = "A client written in Ruby and published as a gem for communicating with the work-auth server"
14
+ spec.homepage = "https://github.com/asinner/work-auth-client"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "rest-client"
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_auth_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Sinner
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-03 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: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
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
+ description: A client written in Ruby and published as a gem for communicating with
56
+ the work-auth server
57
+ email:
58
+ - andrewsinner@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/work_auth_client.rb
70
+ - lib/work_auth_client/version.rb
71
+ - work_auth_client.gemspec
72
+ homepage: https://github.com/asinner/work-auth-client
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.0.1
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Ruby work-auth client
94
+ test_files: []