omniauth-fishbrain 0.9.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: 18b08b84c82f3c10704e309debd002b2a05bfba8c3f9392028325339fdab0f61
4
+ data.tar.gz: fc941f8c41c630491831e79f828f07621be3e1fc80ca91a7f7fe93f64cad926a
5
+ SHA512:
6
+ metadata.gz: 1ad8cff223e86137c99d924b0bdd8cf2146393738419b13163d2ae5dd69b3678967e71ce96f9cd8422b77080eaf6186edd9c1064ab9c4870e8d99dca5ff31848
7
+ data.tar.gz: cc450625016d5ee861732382fdf868ec42c4291f453358729f1d28c530978bd0d5bffd6e41a9e35b8c0b8fedade712a902c1f96ab4f06423f1f81c7f9a16e99d
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Fishbrain
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # omniauth-fishbrain
2
+
3
+ OmniAuth strategy for authenticating with Fishbrain
4
+
5
+ ## Installation
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'omniauth-google-oauth2'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Usage
16
+
17
+ Add something like the following to add the fishbrain authentication stategy.
18
+
19
+ ```
20
+ use OmniAuth::Builder do
21
+ provider :fishbrain, ENV.fetch('FISHBRAIN_CLIENT_ID'), ENV.fetch('FISHBRAIN_CLIENT_SECRET')
22
+ end
23
+ ```
24
+
25
+ See `/examples` for a full example using Sinatra & Omniauth.
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) {|repo_name| 'https://github.com/#{repo_name}' }
6
+
7
+ gem 'sinatra'
8
+ gem 'omniauth'
9
+ gem 'haml'
10
+ gem 'omniauth-fishbrain'
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'sinatra/base'
5
+ require 'omniauth'
6
+ require 'omniauth-fishbrain'
7
+ require 'pp'
8
+
9
+ # Example Sinatra+Omniauth+Fishbrain app
10
+ class FishbrainExample < Sinatra::Application
11
+ configure do
12
+ set :sessions, true
13
+ set :haml, format: :html5
14
+ end
15
+ use OmniAuth::Builder do
16
+ provider :fishbrain,
17
+ ENV.fetch('FISHBRAIN_CLIENT_ID'),
18
+ ENV.fetch('FISHBRAIN_CLIENT_SECRET')
19
+ end
20
+
21
+ get '/' do
22
+ haml :index
23
+ end
24
+
25
+ get '/auth/failure' do
26
+ haml :auth_failure
27
+ end
28
+
29
+ get '/auth/:provider/callback' do
30
+ haml :callback
31
+ end
32
+
33
+ run! if app_file == $PROGRAM_NAME
34
+ end
@@ -0,0 +1,10 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title
5
+ Cognito auth example
6
+ %body
7
+ %h1
8
+ Authentication failure
9
+
10
+ %pre= params['message']
@@ -0,0 +1,9 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title
5
+ Cognito auth example
6
+ %body
7
+ %h1= params[:provider]
8
+
9
+ %pre= request.env['omniauth.auth'].pretty_inspect
@@ -0,0 +1,14 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title
5
+ Cognito auth example
6
+ %body
7
+ %h1
8
+ Welcome
9
+
10
+ %a{ href: "/auth/fishbrain" }
11
+ Log in with Fishbrain
12
+
13
+ %a{ href: "/auth/cognito-idp" }
14
+ Log in with Cognito
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/fishbrain'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/fishbrain'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Fishbrain
5
+ VERSION = '0.9.0'
6
+ end
7
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+ require 'jwt'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # OmniAuth Strategy for Fishbrain
9
+ class Fishbrain < OmniAuth::Strategies::OAuth2
10
+ option :name, 'fishbrain'
11
+ option :client_options,
12
+ site: 'https://accounts.fishbrain.com',
13
+ authorize_url: '/oauth2/authorize',
14
+ token_url: '/oauth2/token',
15
+ auth_scheme: :basic_auth
16
+ option :scope, 'email openid profile'
17
+ option :jwt_leeway, 60
18
+ option :user_pool_id, 'eu-west-1_5r0WbR8OH'
19
+ option :aws_region, 'eu-west-1'
20
+
21
+ uid do
22
+ parsed_id_token['sub'] if parsed_id_token
23
+ end
24
+
25
+ info do
26
+ if parsed_id_token
27
+ {
28
+ name: parsed_id_token['name'],
29
+ email: parsed_id_token['email'],
30
+ phone: parsed_id_token['phone_number']
31
+ }
32
+ end
33
+ end
34
+
35
+ credentials do
36
+ { token: access_token.token }.tap do |hash|
37
+ hash[:refresh_token] = access_token.refresh_token if access_token.expires? && access_token.refresh_token
38
+ hash[:expires_at] = access_token.expires_at if access_token.expires?
39
+ hash[:expires] = access_token.expires?
40
+ hash[:id_token] = id_token if id_token
41
+ end
42
+ end
43
+
44
+ extra do
45
+ { raw_info: parsed_id_token.reject { |key| %w[iss aud exp iat token_use nbf].include?(key) } }
46
+ end
47
+
48
+ private
49
+
50
+ # Override this method to remove the query string from the callback_url because Cognito
51
+ # requires an exact match
52
+ def build_access_token
53
+ client.auth_code.get_token(
54
+ request.params['code'],
55
+ { redirect_uri: callback_url.split('?').first }.merge(token_params.to_hash(symbolize_keys: true)),
56
+ deep_symbolize(options.auth_token_params)
57
+ )
58
+ end
59
+
60
+ def id_token
61
+ access_token && access_token['id_token']
62
+ end
63
+
64
+ def parsed_id_token
65
+ return nil unless id_token
66
+
67
+ @parsed_id_token ||= JWT.decode(
68
+ id_token,
69
+ nil,
70
+ false,
71
+ verify_iss: options[:aws_region] && options[:user_pool_id],
72
+ iss: "https://cognito-idp.#{options[:aws_region]}.amazonaws.com/#{options[:user_pool_id]}",
73
+ verify_aud: true,
74
+ aud: options[:client_id],
75
+ verify_sub: true,
76
+ verify_expiration: true,
77
+ verify_not_before: true,
78
+ verify_iat: true,
79
+ verify_jti: false,
80
+ leeway: options[:jwt_leeway]
81
+ ).first
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'omniauth', 'fishbrain', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = 'omniauth-fishbrain'
10
+ gem.version = OmniAuth::Fishbrain::VERSION
11
+ gem.license = 'MIT'
12
+ gem.summary = %(A Fishbrain strategy for OmniAuth 1.x)
13
+ gem.description = %(A Fishbrain strategy for OmniAuth 1.x. This allows you to login to Fishbrain with your ruby app.)
14
+ gem.authors = ['Erik Dalen']
15
+ gem.email = ['erik.dalen@fishbrain.com']
16
+ gem.homepage = 'https://github.com/fishbrain/omniauth-fishbrain'
17
+
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.required_ruby_version = '>= 2.2'
22
+
23
+ gem.add_runtime_dependency 'jwt', '~> 2.0'
24
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.6'
25
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-fishbrain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Erik Dalen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: A Fishbrain strategy for OmniAuth 1.x. This allows you to login to Fishbrain
42
+ with your ruby app.
43
+ email:
44
+ - erik.dalen@fishbrain.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - LICENSE
51
+ - README.md
52
+ - examples/sinatra/Gemfile
53
+ - examples/sinatra/fishbrain_example.rb
54
+ - examples/sinatra/views/auth_failure.haml
55
+ - examples/sinatra/views/callback.haml
56
+ - examples/sinatra/views/index.haml
57
+ - lib/omniauth-fishbrain.rb
58
+ - lib/omniauth/fishbrain.rb
59
+ - lib/omniauth/fishbrain/version.rb
60
+ - lib/omniauth/strategies/fishbrain.rb
61
+ - omniauth-fishbrain.gemspec
62
+ homepage: https://github.com/fishbrain/omniauth-fishbrain
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '2.2'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.7.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A Fishbrain strategy for OmniAuth 1.x
86
+ test_files: []