omniauth-authsch 0.9.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: 6390054019bf6e152495e6a2415c1ef7c4c74e91
4
+ data.tar.gz: edf64593e18dd1e1654e3e4f6811900ecf64c00a
5
+ SHA512:
6
+ metadata.gz: 7e3d5ba9b48e38fdbd2ed3f8d475bd36a092880d5cbbb56dc59f46802159bed5151c1a9123505e5966b60480662fbb01da3f8db1f040eeb9e6fea9a4baed7e05
7
+ data.tar.gz: 4733ae21a3c0ebded4e891bbaae2ae532a57e000942a641961fc79093b713764fd12f847ec41ae950a785d335bd2f96292caac8db2801524a977128260684d74
@@ -0,0 +1,5 @@
1
+ # IDE files
2
+ .idea/
3
+
4
+ # Temporary files
5
+ *.gem
@@ -0,0 +1,6 @@
1
+ Metrics/BlockLength:
2
+ ExcludedMethods: ['describe', 'context']
3
+ Metrics/LineLength:
4
+ Enabled: false
5
+ Style/FileName:
6
+ Enabled: false
@@ -0,0 +1,91 @@
1
+ # OmniAuth Auth.sch Strategy
2
+
3
+ Strategy to authenticate with Auth.sch in OmniAuth.
4
+
5
+ Get your API key at: http://auth.sch.bme.hu
6
+
7
+ ## Installation
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-authsch'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage with Devise
18
+
19
+ First define your application id and secret in `config/initializers/devise.rb`.
20
+
21
+ Configuration options can be passed as the last parameter here as key/value pairs.
22
+
23
+ ```ruby
24
+ config.omniauth :authsch, ENV['AUTHSCH_CLIENT'], ENV['AUTHSCH_KEY'], scope: ENV['AUTHSCH_SCOPES']
25
+ ```
26
+
27
+ Then add the following to `config/routes.rb` so the callback routes are defined.
28
+
29
+ ```ruby
30
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
31
+ ```
32
+
33
+ Make sure your model is omniauthable. Generally this is `app/models/user.rb`
34
+
35
+ ```ruby
36
+ devise :omniauthable, omniauth_providers: [:authsch]
37
+ ```
38
+
39
+ Then make sure your callbacks controller is setup in `app/controllers/users/omniauth_callbacks_controller.rb`
40
+
41
+ ```ruby
42
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
43
+ def authsch
44
+ # You need to implement the method below in your model (e.g. app/models/user.rb)
45
+ @user = User.from_omniauth(request.env['omniauth.auth'])
46
+
47
+ if @user.persisted?
48
+ flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Auth.sch'
49
+ sign_in_and_redirect @user, event: :authentication
50
+ else
51
+ redirect_to root_path, alert: @user.errors.full_messages.join('\n')
52
+ end
53
+ end
54
+ end
55
+ ```
56
+
57
+ and bind to or create the user in `app/models/user.rb`
58
+
59
+ ```ruby
60
+ def self.from_omniauth(access_token)
61
+ data = access_token.info
62
+ user = User.where(email: data['email']).first
63
+
64
+ # Uncomment the section below if you want users to be created if they don't exist
65
+ # unless user
66
+ # user = User.create(name: data['name'],
67
+ # email: data['email'],
68
+ # password: Devise.friendly_token[0,20]
69
+ # )
70
+ # end
71
+ user
72
+ end
73
+ ```
74
+
75
+ For your views you can login using:
76
+
77
+ ```erb
78
+ <%= link_to "Sign in with Auth.sch", user_authsch_omniauth_authorize_path %>
79
+ ```
80
+
81
+ An overview is available at https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
82
+
83
+ ## License
84
+
85
+ Copyright (c) 2017 by Zsolt Kozaroczy
86
+
87
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
88
+
89
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
90
+
91
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/authsch'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/strategies/authsch'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Authsch
5
+ VERSION = '0.9.0'.freeze
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'multi_json'
4
+ require 'omniauth/strategies/oauth2'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # Main class for Auth.sch strategy.
9
+ class Authsch < OmniAuth::Strategies::OAuth2
10
+ option :name, 'authsch'
11
+
12
+ option :client_options,
13
+ site: 'http://auth.sch.bme.hu',
14
+ authorize_url: '/site/login',
15
+ token_url: '/oauth2/token'
16
+
17
+ option :authorize_params, grant_type: 'authorization_code'
18
+
19
+ def authorize_params
20
+ super.tap do |params|
21
+ params[:scope] = request.params['scope'] if request.params['scope']
22
+ end
23
+ end
24
+
25
+ uid { raw_info['internal_id'].to_s }
26
+
27
+ info do
28
+ {
29
+ id: raw_info['internal_id'],
30
+ email: raw_info['mail']
31
+ }
32
+ end
33
+
34
+ extra do
35
+ { raw_info: raw_info }
36
+ end
37
+
38
+ def raw_info
39
+ access_token.options[:parse] = :json
40
+
41
+ url = '/api/profile'
42
+ params = { params: { access_token: access_token.token } }
43
+ @raw_info ||= MultiJson.decode(access_token.client.request(:get, url, params).body)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+
4
+ require File.expand_path(
5
+ File.join('..', 'lib', 'omniauth', 'authsch', 'version'),
6
+ __FILE__
7
+ )
8
+
9
+ Gem::Specification.new do |gem|
10
+ gem.name = 'omniauth-authsch'
11
+ gem.version = OmniAuth::Authsch::VERSION
12
+ gem.license = 'MIT'
13
+ gem.summary = 'An Auth.sch strategy for OmniAuth 1.x'
14
+ gem.description = 'An Auth.sch strategy for OmniAuth 1.x. This allows you to login to Auth.sch with your ruby app.'
15
+ gem.authors = ['Zsolt Kozaroczy']
16
+ gem.email = ['kiskoza@sch.bme.hu']
17
+ gem.homepage = 'https://github.com/kiskoza/omniauth-authsch'
18
+
19
+ gem.files = `git ls-files`.split("\n")
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.required_ruby_version = '>= 2.0'
23
+
24
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
25
+
26
+ gem.add_development_dependency 'rspec', '~> 3.6'
27
+ gem.add_development_dependency 'rake', '~> 12.0'
28
+ gem.add_development_dependency 'rubocop', '~> 0.49'
29
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'omniauth-authsch'
5
+
6
+ describe OmniAuth::Strategies::Authsch do
7
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
8
+ let(:app) do
9
+ lambda do
10
+ [200, {}, ['Hello.']]
11
+ end
12
+ end
13
+
14
+ subject do
15
+ OmniAuth::Strategies::Authsch.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
16
+ allow(strategy).to receive(:request) do
17
+ request
18
+ end
19
+ end
20
+ end
21
+
22
+ before do
23
+ OmniAuth.config.test_mode = true
24
+ end
25
+
26
+ after do
27
+ OmniAuth.config.test_mode = false
28
+ end
29
+
30
+ describe '#client_options' do
31
+ it 'has correct site' do
32
+ expect(subject.client.site).to eq('http://auth.sch.bme.hu')
33
+ end
34
+
35
+ it 'has correct authorize_url' do
36
+ expect(subject.client.options[:authorize_url]).to eq('/site/login')
37
+ end
38
+
39
+ it 'has correct token_url' do
40
+ expect(subject.client.options[:token_url]).to eq('/oauth2/token')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe 'Rubocop' do
6
+ it 'should pass with no offenses detected' do
7
+ expect(`rubocop`).to include('no offenses detected')
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join('bundler', 'setup')
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-authsch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Zsolt Kozaroczy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.49'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.49'
69
+ description: An Auth.sch strategy for OmniAuth 1.x. This allows you to login to Auth.sch
70
+ with your ruby app.
71
+ email:
72
+ - kiskoza@sch.bme.hu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rubocop.yml"
79
+ - Readme.md
80
+ - lib/omniauth-authsch.rb
81
+ - lib/omniauth/authsch.rb
82
+ - lib/omniauth/authsch/version.rb
83
+ - lib/omniauth/strategies/authsch.rb
84
+ - omniauth-authsch.gemspec
85
+ - spec/omniauth/startegies/authsch_spec.rb
86
+ - spec/rubocop_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/kiskoza/omniauth-authsch
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '2.0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: An Auth.sch strategy for OmniAuth 1.x
112
+ test_files: []