google_auth_box 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: ae4b107dee7089019ad581e728f334c8f68d1a6e
4
+ data.tar.gz: 1ffd7a9e67d1b2ea9812b3a71157d9215d3d7f27
5
+ SHA512:
6
+ metadata.gz: 5b8d07e0ace0905ef12ed270b05db5d19e2298fba0773559fa7cc85bc8ec8f2a822f708e74507863e51ccf3115abffa3dc3309035cd4571b4f8d74c1c03da033
7
+ data.tar.gz: 361ba158b8c1ed6e6b36388e362bbb565f1b907224619796e5a607c6a7255e5b06967b802bbc182a07b0879ceec2b9ac5947d86861cf5fdefe1b8491c74d110a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0
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 google_auth_box.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ google_auth_box (0.1.0)
5
+ googleauth (~> 0.6.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ faraday (0.14.0)
15
+ multipart-post (>= 1.2, < 3)
16
+ ffi (1.9.23)
17
+ formatador (0.2.5)
18
+ googleauth (0.6.2)
19
+ faraday (~> 0.12)
20
+ jwt (>= 1.4, < 3.0)
21
+ logging (~> 2.0)
22
+ memoist (~> 0.12)
23
+ multi_json (~> 1.11)
24
+ os (~> 0.9)
25
+ signet (~> 0.7)
26
+ guard (2.14.2)
27
+ formatador (>= 0.2.4)
28
+ listen (>= 2.7, < 4.0)
29
+ lumberjack (>= 1.0.12, < 2.0)
30
+ nenv (~> 0.1)
31
+ notiffany (~> 0.0)
32
+ pry (>= 0.9.12)
33
+ shellany (~> 0.0)
34
+ thor (>= 0.18.1)
35
+ guard-compat (1.2.1)
36
+ guard-rspec (4.7.3)
37
+ guard (~> 2.1)
38
+ guard-compat (~> 1.1)
39
+ rspec (>= 2.99.0, < 4.0)
40
+ jwt (2.1.0)
41
+ listen (3.1.5)
42
+ rb-fsevent (~> 0.9, >= 0.9.4)
43
+ rb-inotify (~> 0.9, >= 0.9.7)
44
+ ruby_dep (~> 1.2)
45
+ little-plugger (1.1.4)
46
+ logging (2.2.2)
47
+ little-plugger (~> 1.1)
48
+ multi_json (~> 1.10)
49
+ lumberjack (1.0.12)
50
+ memoist (0.16.0)
51
+ method_source (0.9.0)
52
+ multi_json (1.13.1)
53
+ multipart-post (2.0.0)
54
+ nenv (0.3.0)
55
+ notiffany (0.1.1)
56
+ nenv (~> 0.1)
57
+ shellany (~> 0.0)
58
+ os (0.9.6)
59
+ pry (0.11.3)
60
+ coderay (~> 1.1.0)
61
+ method_source (~> 0.9.0)
62
+ public_suffix (3.0.2)
63
+ rake (10.5.0)
64
+ rb-fsevent (0.10.3)
65
+ rb-inotify (0.9.10)
66
+ ffi (>= 0.5.0, < 2)
67
+ rspec (3.7.0)
68
+ rspec-core (~> 3.7.0)
69
+ rspec-expectations (~> 3.7.0)
70
+ rspec-mocks (~> 3.7.0)
71
+ rspec-core (3.7.1)
72
+ rspec-support (~> 3.7.0)
73
+ rspec-expectations (3.7.0)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.7.0)
76
+ rspec-mocks (3.7.0)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.7.0)
79
+ rspec-support (3.7.1)
80
+ ruby_dep (1.5.0)
81
+ shellany (0.0.1)
82
+ signet (0.8.1)
83
+ addressable (~> 2.3)
84
+ faraday (~> 0.9)
85
+ jwt (>= 1.5, < 3.0)
86
+ multi_json (~> 1.10)
87
+ thor (0.20.0)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 1.16)
94
+ google_auth_box!
95
+ guard-rspec
96
+ rake (~> 10.0)
97
+ rspec (~> 3.0)
98
+
99
+ BUNDLED WITH
100
+ 1.16.0
data/Guardfile ADDED
@@ -0,0 +1,74 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+
71
+ watch(%r{^spec/.+_spec\.rb$})
72
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
73
+ watch('spec/spec_helper.rb') { "spec" }
74
+ end
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # GoogleAuthBox
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/google_auth_box`. 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 'google_auth_box'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install google_auth_box
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require './lib/google_auth_box/client'
27
+ f = File.new './secret.json'
28
+
29
+ # go to google developer console
30
+ # to enable an api and download client_secrets as a json file
31
+ # then just load it and pass it as a Hash to the GAB::Client
32
+ client_data = JSON.parse(f.read)
33
+
34
+ # the client also takes scopes, a plain file for the data store
35
+ # and a callback where the refresh tokens will be sent
36
+ # don't worry about a refresh token, just expost an endpoint
37
+ # that can take a url with a query string param "code"
38
+ # and mayb gree the user with a nice response ;)
39
+ client = GoogleAuthBox::Client.new(
40
+ client_id_hash: client_data,
41
+ scopes: ['https://www.googleapis.com/auth/spreadsheets'],
42
+ data_file_path: './data.yml',
43
+ base_uri: 'http://mycooluri/oathcallback'
44
+ )
45
+
46
+ # grab this and send it to the user
47
+ p client.get_auth_url
48
+
49
+ # sometime later
50
+ # this would probably involve sending the url and receiving a api call
51
+ # with the base_uri above. the query param "code" will contain the
52
+ # refresh token for google auth
53
+ code = '5/alongcode'
54
+ client.save_creds 7, code
55
+
56
+ # at this point the client with an id 7 will have their credentials persisted
57
+ p client.get_creds 7
58
+
59
+ ```
60
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "google_auth_box"
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,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "google_auth_box/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "google_auth_box"
8
+ spec.version = GoogleAuthBox::VERSION
9
+ spec.authors = ["axylos"]
10
+ spec.email = ["robertdraketalley@gmail.com"]
11
+
12
+ spec.summary = %q{Google Auth Wrapper in a Box}
13
+ spec.description = %q{For people who never want to know what "three legged auth" means}
14
+ spec.homepage = "http://draketalley.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "googleauth", "~> 0.6.2"
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "guard-rspec"
28
+ end
@@ -0,0 +1,3 @@
1
+ require "google_auth_box/version"
2
+
3
+ require 'google_auth_box/client'
@@ -0,0 +1,41 @@
1
+ require 'googleauth'
2
+ require 'googleauth/stores/file_token_store'
3
+ module GoogleAuthBox
4
+ class Client
5
+ def initialize(client_id_hash:, scopes:, data_file_path:, base_uri:)
6
+ @base_uri = base_uri
7
+
8
+ client_id = Google::Auth::ClientId.from_hash client_id_hash
9
+ f = File.open data_file_path
10
+ data_path = File.absolute_path f
11
+ token_store = Google::Auth::Stores::FileTokenStore.new(
12
+ :file => data_path
13
+ )
14
+
15
+ f.close
16
+
17
+ @auth_client = Google::Auth::UserAuthorizer.new(
18
+ client_id,
19
+ scopes,
20
+ token_store,
21
+ base_uri
22
+ )
23
+
24
+ def get_auth_url
25
+ @auth_client.get_authorization_url(base_url: @base_uri)
26
+ end
27
+
28
+ def get_creds(id)
29
+ @auth_client.get_credentials(id)
30
+ end
31
+
32
+ def save_creds(id, code)
33
+ @auth_client.get_and_store_credentials_from_code(
34
+ user_id: id,
35
+ code: code,
36
+ base_url: @base_uri
37
+ )
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module GoogleAuthBox
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_auth_box
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - axylos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: googleauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.2
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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: For people who never want to know what "three legged auth" means
84
+ email:
85
+ - robertdraketalley@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - Guardfile
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - google_auth_box.gemspec
101
+ - lib/google_auth_box.rb
102
+ - lib/google_auth_box/client.rb
103
+ - lib/google_auth_box/version.rb
104
+ homepage: http://draketalley.com
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.14
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Google Auth Wrapper in a Box
127
+ test_files: []