omniauth-okta 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38df3b55712de59cb23523883470194544d4bce3
4
+ data.tar.gz: 216d413ed26f5d19e9cd30891a2d3594e17d8990
5
+ SHA512:
6
+ metadata.gz: 0e7b53deafd73f07efee1f988cdee305542dbbefdbae4a1d7d0e63309a2bc0bac91502b816e9ac77ac5561302bc5c03f935a72307fc7ceb0849508624ce5fd6f
7
+ data.tar.gz: 88199e697905e10481d5c5b7e3cb1af8f766b17a1f03f6059cbf4b86341840a163777c3b8837d94abd87796da70074dc0ac925d33c2a8a0681dded3baac31e45
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Dan Andrews
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,139 @@
1
+ # OmniAuth Okta OAuth2 Strategy
2
+
3
+ Strategy to authenticate with Okta via OAuth2 in OmniAuth.
4
+
5
+ This strategy uses Okta's OpenID Connect API with OAuth2. See their [developer docs](https://developer.okta.com/docs/api/resources/oidc.html) for more details.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-okta'
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle install
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ $ gem install omniauth-okta
23
+ ```
24
+
25
+ ### Environment Variables
26
+
27
+ ```bash
28
+ OKTA_CLIENT_ID # required
29
+ OKTA_CLIENT_SECRET # required
30
+ OKTA_ORG # required - defaults to 'your-org' if unset
31
+ OKTA_DOMAIN # optional - defaults to 'okta.com' if unset
32
+ ```
33
+
34
+ ### OmniAuth
35
+
36
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :okta, ENV['OKTA_CLIENT_ID'], ENV['OKTA_CLIENT_SECRET']
41
+ end
42
+ ```
43
+
44
+ ### Devise
45
+
46
+ First define your application id and secret in `config/initializers/devise.rb`.
47
+
48
+ Configuration options can be passed as the last parameter here as key/value pairs.
49
+
50
+ ```ruby
51
+ config.omniauth :okta, ENV['OKTA_CLIENT_ID'], ENV['OKTA_CLIENT_SECRET'], {}
52
+ ```
53
+ or add options like the following:
54
+
55
+ ```ruby
56
+ require 'omniauth-okta'
57
+ config.omniauth(:okta,
58
+ ENV['OKTA_CLIENT_ID'],
59
+ ENV['OKTA_CLIENT_SECRET'],
60
+ :scope => 'openid profile email',
61
+ :fields => ['profile', 'email'],
62
+ :strategy_class => OmniAuth::Strategies::Okta)
63
+ ```
64
+
65
+ Then add the following to 'config/routes.rb' so the callback routes are defined.
66
+
67
+ ```ruby
68
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
69
+ ```
70
+
71
+ Make sure your model is omniauthable. Generally this is "/app/models/user.rb"
72
+
73
+ ```ruby
74
+ devise :omniauthable, omniauth_providers: [:okta]
75
+ ```
76
+
77
+ ## Auth Hash
78
+
79
+ Here's an example of an authentication hash available in the callback by accessing `request.env['omniauth.auth']`:
80
+
81
+ ```ruby
82
+ {
83
+ "provider" => "okta",
84
+ "uid" => "0000000000000001",
85
+ "info" => {
86
+ "name" => "John Smith",
87
+ "email" => "john@example.com",
88
+ "first_name" => "John",
89
+ "last_name" => "Smith",
90
+ "image" => "https://photohosting.com/john.jpg"
91
+ },
92
+ "credentials" => {
93
+ "token" => "TOKEN",
94
+ "expires_at" => 1496617411,
95
+ "expires" => true
96
+ },
97
+ "extra" => {
98
+ "raw_info" => {
99
+ "sub" => "0000000000000001",
100
+ "name" => "John Smith",
101
+ "locale" => "en-US",
102
+ "email" => "john@example.com",
103
+ "picture" => "https://photohosting.com/john.jpg",
104
+ "website" => "https://example.com",
105
+ "preferred_username" => "john@example.com",
106
+ "given_name" => "John",
107
+ "family_name" => "Smith",
108
+ "zoneinfo" => "America/Los_Angeles",
109
+ "updated_at" => 1496611646,
110
+ "email_verified" => true
111
+ },
112
+ "id_token" => "TOKEN",
113
+ "id_info" => {
114
+ "ver" => 1,
115
+ "jti" => "AT.D2sslkfjdsldjf899n090sldkfj",
116
+ "iss" => "https://your-org.okta.com",
117
+ "aud" => "https://your-org.okta.com",
118
+ "sub" => "john@example.com",
119
+ "iat" => 1496613811,
120
+ "exp" => 1496617411,
121
+ "cid" => "CLIENT_ID",
122
+ "uid" => "0000000000000001",
123
+ "scp" => ["email", "profile", "openid"]
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ ## Contributing
130
+
131
+ 1. Fork it
132
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
133
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
134
+ 4. Push to the branch (`git push origin my-new-feature`)
135
+ 5. Create new Pull Request
136
+
137
+ ## License
138
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
139
+
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Omniauth::Okta'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth-okta/version"
4
+ require "omniauth/strategies/okta"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Okta
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Okta < OmniAuth::Strategies::OAuth2
8
+
9
+ ORG = ENV['OKTA_ORG'] || 'your-org'
10
+ DOMAIN = ENV['OKTA_DOMAIN'] || 'okta'
11
+ BASE_URL = "https://#{ORG}.#{DOMAIN}.com"
12
+ DEFAULT_SCOPE = %[openid profile email].freeze
13
+
14
+ option :name, 'okta'
15
+
16
+ option :skip_jwt, false
17
+ option :jwt_leeway, 60
18
+
19
+ option :client_options, {
20
+ site: BASE_URL,
21
+ authorize_url: "#{BASE_URL}/oauth2/v1/authorize",
22
+ token_url: "#{BASE_URL}/oauth2/v1/token",
23
+ response_type: 'id_token'
24
+ }
25
+
26
+ option :scope, DEFAULT_SCOPE
27
+
28
+ uid { raw_info['sub'] }
29
+
30
+ info do
31
+ {
32
+ name: raw_info['name'],
33
+ email: raw_info['email'],
34
+ first_name: raw_info['given_name'],
35
+ last_name: raw_info['family_name'],
36
+ image: raw_info['picture']
37
+ }
38
+ end
39
+
40
+ extra do
41
+ hash = {}
42
+ hash[:raw_info] = raw_info unless skip_info?
43
+ hash[:id_token] = access_token.token
44
+ if !options[:skip_jwt] && !access_token.token.nil?
45
+ hash[:id_info] = validated_token(access_token.token)
46
+ end
47
+ hash
48
+ end
49
+
50
+ alias :oauth2_access_token :access_token
51
+
52
+ def access_token
53
+ ::OAuth2::AccessToken.new(client, oauth2_access_token.token, {
54
+ :expires_in => oauth2_access_token.expires_in,
55
+ :expires_at => oauth2_access_token.expires_at
56
+ })
57
+ end
58
+
59
+ def raw_info
60
+ @_raw_info ||= access_token.get('/oauth2/v1/userinfo').parsed || {}
61
+ rescue ::Errno::ETIMEDOUT
62
+ raise ::Timeout::Error
63
+ end
64
+
65
+ def request_phase
66
+ super
67
+ end
68
+
69
+ def callback_phase
70
+ super
71
+ end
72
+
73
+ def callback_url
74
+ options[:redirect_uri] || (full_host + script_name + callback_path)
75
+ end
76
+
77
+ def validated_token(token)
78
+ JWT.decode(token,
79
+ nil,
80
+ false,
81
+ verify_iss: true,
82
+ iss: BASE_URL,
83
+ verify_aud: true,
84
+ aud: BASE_URL,
85
+ verify_sub: true,
86
+ verify_expiration: true,
87
+ verify_not_before: true,
88
+ verify_iat: true,
89
+ verify_jti: false,
90
+ leeway: options[:jwt_leeway]
91
+ ).first
92
+ end
93
+ end
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-okta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Andrews
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Unofficial OmniAuth OAuth2 strategy for Okta
98
+ email:
99
+ - daniel.raymond.andrews@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - lib/omniauth-okta.rb
108
+ - lib/omniauth-okta/version.rb
109
+ - lib/omniauth/strategies/okta.rb
110
+ homepage: ''
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.8
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Unofficial OmniAuth OAuth2 strategy for Okta
134
+ test_files: []