omniauth-dex-energy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ab01bbe6688b0dbe03fa53e4e219a6fb90ef2cc922c49626b682c4394de9e1a9
4
+ data.tar.gz: 4b596e91ef5070d7744bd82caa22314234c3020ba7b567a874be35c3bb934b21
5
+ SHA512:
6
+ metadata.gz: b145dff303792f5ff20aa64c9647951efddd66f9a521f101318ae8d6fcc57337ff88b9d546dce9487e711c25afe2f731bb34d22bbac491255278bfc1c5cd1cbd
7
+ data.tar.gz: d14725cff0d870f6e47472564d4db35da086240aea94d53b625998d458ff03ce1650acd24e0129663878d54c8445a5930dd29af7b9c4bc6c46940a7c3c494995
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # omniauth-dex-energy
2
+
3
+ ![CI](https://github.com/greensync/omniauth-dex-energy/workflows/CI/badge.svg)
4
+
5
+ An OmniAuth strategy to authenticate with deX.
6
+
7
+ ## Table of Contents
8
+
9
+ - [omniauth-dex-energy](#omniauth-dex-energy)
10
+ - [Table of Contents](#table-of-contents)
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [First Steps](#first-steps)
14
+ - [Sinatra](#sinatra)
15
+ - [Development](#development)
16
+ - [Contributing](#contributing)
17
+ - [License](#license)
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'omniauth-dex-energy'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install omniauth-dex-energy
34
+
35
+ ## Usage
36
+
37
+ ### First Steps
38
+
39
+ Regardless of your web framework, you will need to provision an OAuth2 Client in the IdP through the [GreenSync Platform Team](mailto:internalplatform@greensync.com.au). You'll be provided with a Client ID and Client Secret that can be used to configure this gem.
40
+
41
+ Contact the [GreenSync Platform Team].
42
+
43
+ ### Sinatra
44
+
45
+ See [`examples/sinatra/app.rb`](examples/sinatra/app.rb) for example usage.
46
+
47
+ To run the example application:
48
+
49
+ ```bash
50
+ export OAUTH2_CLIENT_ID='my-client-id'
51
+ export OAUTH2_CLIENT_SECRET='my-client-secret'
52
+
53
+ cd examples/sinatra
54
+ bundle install
55
+ bundle exec foreman start
56
+ ```
57
+
58
+ ## Development
59
+
60
+ 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.
61
+
62
+ 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).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/greensync/omniauth-dex-energy.
67
+
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'omniauth/strategies/dex_energy'
6
+
7
+ require 'pry-byebug'
8
+
9
+ Pry.start
data/bin/publish-gem ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ set -Eeuo pipefail
4
+
5
+ set -x
6
+
7
+ version=$(cat $(dirname $0)/../VERSION)
8
+
9
+ gem build omniauth-dex-energy
10
+ gem push omniauth-dex-energy-${version}.gem
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,8 @@
1
+ gem 'omniauth-dex-energy'
2
+ gem 'puma'
3
+ gem 'sinatra'
4
+ gem 'slim'
5
+
6
+ group 'development' do
7
+ gem 'foreman'
8
+ end
@@ -0,0 +1,56 @@
1
+ GEM
2
+ specs:
3
+ faraday (1.0.0)
4
+ multipart-post (>= 1.2, < 3)
5
+ foreman (0.86.0)
6
+ hashie (3.6.0)
7
+ jwt (2.2.1)
8
+ multi_json (1.14.1)
9
+ multi_xml (0.6.0)
10
+ multipart-post (2.1.1)
11
+ mustermann (1.1.0)
12
+ ruby2_keywords (~> 0.0.1)
13
+ nio4r (2.5.2)
14
+ oauth2 (1.4.3)
15
+ faraday (>= 0.8, < 2.0)
16
+ jwt (>= 1.0, < 3.0)
17
+ multi_json (~> 1.3)
18
+ multi_xml (~> 0.5)
19
+ rack (>= 1.2, < 3)
20
+ omniauth (1.9.0)
21
+ hashie (>= 3.4.6, < 3.7.0)
22
+ rack (>= 1.6.2, < 3)
23
+ omniauth-dex-energy (0.1.0)
24
+ omniauth-oauth2 (~> 1.6.0)
25
+ omniauth-oauth2 (1.6.0)
26
+ oauth2 (~> 1.1)
27
+ omniauth (~> 1.9)
28
+ puma (4.3.1)
29
+ nio4r (~> 2.0)
30
+ rack (2.2.2)
31
+ rack-protection (2.0.8.1)
32
+ rack
33
+ ruby2_keywords (0.0.1)
34
+ sinatra (2.0.8.1)
35
+ mustermann (~> 1.0)
36
+ rack (~> 2.0)
37
+ rack-protection (= 2.0.8.1)
38
+ tilt (~> 2.0)
39
+ slim (4.0.1)
40
+ temple (>= 0.7.6, < 0.9)
41
+ tilt (>= 2.0.6, < 2.1)
42
+ temple (0.8.2)
43
+ tilt (2.0.10)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ foreman
50
+ omniauth-dex-energy
51
+ puma
52
+ sinatra
53
+ slim
54
+
55
+ BUNDLED WITH
56
+ 2.1.2
@@ -0,0 +1 @@
1
+ web: proc/web
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/dex_energy'
4
+ require 'sinatra'
5
+ require 'slim'
6
+
7
+ oauth2_client_id = ENV['OAUTH2_CLIENT_ID']
8
+ oauth2_client_secret = ENV['OAUTH2_CLIENT_SECRET']
9
+
10
+ use Rack::Session::Cookie
11
+
12
+ use OmniAuth::Builder do
13
+ provider :dex_energy, oauth2_client_id, oauth2_client_secret
14
+ end
15
+
16
+ get '/' do
17
+ @user = session[:user]
18
+ slim :hello
19
+ end
20
+
21
+ get '/login' do
22
+ # Redirect the user to the endpoint provided by OmniAuth.
23
+ redirect to("/auth/dex_energy?origin=#{URI.encode_www_form_component(request.referrer)}")
24
+ end
25
+
26
+ get '/auth/dex_energy/callback' do
27
+ # Handle a completed OAuth2 login flow.
28
+ logger.warn(request.env['omniauth.auth'].to_h)
29
+ session[:user] = request.env.fetch('omniauth.auth').uid
30
+ redirect params.fetch(:origin, '/')
31
+ end
32
+
33
+ get '/logout' do
34
+ # Log the user out of their session in the app - but not in the Identity Provider.
35
+ session.delete(:user)
36
+ redirect request.referrer
37
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'app'
2
+
3
+ run Sinatra::Application
@@ -0,0 +1,4 @@
1
+ #! /bin/bash -eu
2
+
3
+ cd $(dirname $0)/..
4
+ exec bundle exec puma --port ${PORT:-5000}
@@ -0,0 +1,8 @@
1
+ p Hello, #{@user || 'stranger'}!
2
+
3
+ ul
4
+ li
5
+ - if @user
6
+ a href="/logout" Log out
7
+ - else
8
+ a href="/login" Log in
@@ -0,0 +1,6 @@
1
+ doctype html
2
+ html
3
+ head
4
+ title deX Auth Test Sinatra App
5
+ body
6
+ == yield
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+ require 'omniauth-oauth2'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class DexEnergy < OmniAuth::Strategies::OAuth2
9
+ option :name, 'dex_energy'
10
+
11
+ option :client_options, site: 'https://who.dex.energy', auth_scheme: :basic_auth
12
+
13
+ uid do
14
+ raw_info['sub']
15
+ end
16
+
17
+ info do
18
+ {
19
+ email: raw_info['email'],
20
+ }
21
+ end
22
+
23
+ extra do
24
+ {
25
+ 'raw_info' => raw_info,
26
+ }
27
+ end
28
+
29
+ private
30
+
31
+ def raw_info
32
+ @raw_info ||= extract_raw_info(access_token)
33
+ end
34
+
35
+ def issuer_url
36
+ options['client_options']['site']
37
+ end
38
+
39
+ def oidc_well_known
40
+ if @well_known.nil?
41
+ uri = URI.parse("#{issuer_url}/.well-known/openid-configuration")
42
+ response = Net::HTTP.get(uri)
43
+ @well_known = JSON.parse(response, symbolize_names: true)
44
+ end
45
+
46
+ @well_known
47
+ end
48
+
49
+ def algorithms
50
+ oidc_well_known[:id_token_signing_alg_values_supported]
51
+ end
52
+
53
+ def jwks
54
+ jwks_uri = oidc_well_known[:jwks_uri]
55
+ uri = URI.parse(jwks_uri)
56
+ response = Net::HTTP.get(uri)
57
+ JSON.parse(response, symbolize_names: true)
58
+ end
59
+
60
+ def jwk_loader
61
+ lambda do |options|
62
+ if @cached_keys.nil? || options[:invalidate]
63
+ # we need to load the keys
64
+ @cached_keys = jwks
65
+ end
66
+
67
+ @cached_keys
68
+ end
69
+ end
70
+
71
+ def extract_raw_info(access_token)
72
+ id_token = access_token.params.fetch('id_token')
73
+
74
+ decoded = JWT.decode(id_token, nil, true,
75
+ algorithms: algorithms,
76
+ jwks: jwk_loader,
77
+ verify_aud: true,
78
+ verify_expiration: true,
79
+ verify_iat: true,
80
+ verify_iss: true,
81
+ verify_jti: true,
82
+ verify_not_before: true,
83
+ verify_sub: true)
84
+
85
+ decoded.first
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'omniauth-dex-energy'
5
+ spec.version = File.read('VERSION').strip
6
+ spec.authors = ['Cera Davies', 'Nick Burgin', 'Mike Williams']
7
+ spec.email = [
8
+ 'internalplatform@greensync.com.au',
9
+ ]
10
+
11
+ spec.summary = 'an OmniAuth strategy for authenticating with deX'
12
+ spec.description = 'an OmniAuth strategy for authenticating with deX'
13
+ spec.homepage = 'https://github.com/greensync/omniauth-dex-energy'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ Dir.glob('{bin,doc,examples,lib}/**/*') + %w[
18
+ README.md omniauth-dex-energy.gemspec
19
+ ]
20
+ end
21
+
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.metadata['homepage_uri'] = spec.homepage
27
+ spec.metadata['source_code_uri'] = spec.homepage
28
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/releases"
29
+
30
+ spec.add_dependency 'omniauth-oauth2', '~> 1.6'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.0'
33
+ spec.add_development_dependency 'pry-byebug', '~> 3.8.0'
34
+ spec.add_development_dependency 'rack', '~> 1.6.0'
35
+ spec.add_development_dependency 'rake', '~> 12.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rubocop', '~> 0.77'
38
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.37.0'
39
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-dex-energy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cera Davies
8
+ - Nick Burgin
9
+ - Mike Williams
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2020-02-28 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth-oauth2
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.6'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: pry-byebug
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.8.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.8.0
57
+ - !ruby/object:Gem::Dependency
58
+ name: rack
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 1.6.0
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.6.0
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '12.0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '12.0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '3.0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '0.77'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0.77'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rubocop-rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 1.37.0
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: 1.37.0
127
+ description: an OmniAuth strategy for authenticating with deX
128
+ email:
129
+ - internalplatform@greensync.com.au
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - README.md
135
+ - bin/console
136
+ - bin/publish-gem
137
+ - bin/setup
138
+ - examples/sinatra/Gemfile
139
+ - examples/sinatra/Gemfile.lock
140
+ - examples/sinatra/Procfile
141
+ - examples/sinatra/app.rb
142
+ - examples/sinatra/config.ru
143
+ - examples/sinatra/proc/web
144
+ - examples/sinatra/views/hello.slim
145
+ - examples/sinatra/views/layout.slim
146
+ - lib/omniauth/strategies/dex_energy.rb
147
+ - omniauth-dex-energy.gemspec
148
+ homepage: https://github.com/greensync/omniauth-dex-energy
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ homepage_uri: https://github.com/greensync/omniauth-dex-energy
153
+ source_code_uri: https://github.com/greensync/omniauth-dex-energy
154
+ changelog_uri: https://github.com/greensync/omniauth-dex-energy/releases
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
+ rubygems_version: 3.0.3
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: an OmniAuth strategy for authenticating with deX
174
+ test_files: []