warden-line 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: bf89e84c98d0ccbd978273e5f310a3ed9e404c2e1b2c0a1165d914801ed01dc3
4
+ data.tar.gz: a6c8f47dbbc5f2a411b703908d7277820da749677ca55dc17509f0e5b714c6d5
5
+ SHA512:
6
+ metadata.gz: 892f8989af1ba3dfa61385bf2746d4dc2a05329d4c88f4fdcfe38be9bc5cecffbf9ec5511d24a0999f381a0dfaae40278585eb24c18fc5dbcb56a053005ee603
7
+ data.tar.gz: f8b698b5e62f02a2dcd8b77e044ba63c69685a22ddfcdf97241d5c90ce853284dce1cd99c7267bc6f55a2be9b77576e8ff464591944c096f521d65a7b29cf2fe
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/.overcommit.yml ADDED
@@ -0,0 +1,17 @@
1
+ PreCommit:
2
+ AuthorName:
3
+ enabled: false
4
+ RuboCop:
5
+ enabled: true
6
+ on_warn: fail # Treat all warnings as failures
7
+ TrailingWhitespace:
8
+ enabled: true
9
+ BundleAudit:
10
+ enabled: true
11
+
12
+ PostCheckout:
13
+ ALL: # Special hook name that customizes all hooks of this type
14
+ quiet: true # Change all post-checkout hooks to only display output on failure
15
+
16
+ IndexTags:
17
+ enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rake
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - spec/**/*.rb
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ - 2.7.0
7
+ before_install: gem install bundler -v 2.1.4
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
12
+ script:
13
+ - bundle exec rspec
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at elct9620@frost.tw. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in warden-line.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+
11
+ gem 'simplecov'
12
+
13
+ gem 'rubocop', '~> 1.8.1'
14
+ gem 'rubocop-rake'
15
+ gem 'rubocop-rspec'
16
+
17
+ gem 'bundler-audit'
18
+ gem 'overcommit'
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ warden-line (0.1.0)
5
+ warden (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ bundler-audit (0.7.0.1)
12
+ bundler (>= 1.2.0, < 3)
13
+ thor (>= 0.18, < 2)
14
+ childprocess (4.0.0)
15
+ diff-lcs (1.4.4)
16
+ docile (1.3.5)
17
+ iniparse (1.5.0)
18
+ overcommit (0.57.0)
19
+ childprocess (>= 0.6.3, < 5)
20
+ iniparse (~> 1.4)
21
+ parallel (1.20.1)
22
+ parser (3.0.0.0)
23
+ ast (~> 2.4.1)
24
+ rack (2.2.3)
25
+ rainbow (3.0.0)
26
+ rake (12.3.3)
27
+ regexp_parser (2.0.3)
28
+ rexml (3.2.4)
29
+ rspec (3.10.0)
30
+ rspec-core (~> 3.10.0)
31
+ rspec-expectations (~> 3.10.0)
32
+ rspec-mocks (~> 3.10.0)
33
+ rspec-core (3.10.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-expectations (3.10.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-mocks (3.10.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-support (3.10.2)
42
+ rubocop (1.8.1)
43
+ parallel (~> 1.10)
44
+ parser (>= 3.0.0.0)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.8, < 3.0)
47
+ rexml
48
+ rubocop-ast (>= 1.2.0, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 3.0)
51
+ rubocop-ast (1.4.1)
52
+ parser (>= 2.7.1.5)
53
+ rubocop-rake (0.5.1)
54
+ rubocop
55
+ rubocop-rspec (2.2.0)
56
+ rubocop (~> 1.0)
57
+ rubocop-ast (>= 1.1.0)
58
+ ruby-progressbar (1.11.0)
59
+ simplecov (0.21.2)
60
+ docile (~> 1.1)
61
+ simplecov-html (~> 0.11)
62
+ simplecov_json_formatter (~> 0.1)
63
+ simplecov-html (0.12.3)
64
+ simplecov_json_formatter (0.1.2)
65
+ thor (1.1.0)
66
+ unicode-display_width (2.0.0)
67
+ warden (1.2.9)
68
+ rack (>= 2.0.9)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ bundler-audit
75
+ overcommit
76
+ rake (~> 12.0)
77
+ rspec (~> 3.0)
78
+ rubocop (~> 1.8.1)
79
+ rubocop-rake
80
+ rubocop-rspec
81
+ simplecov
82
+ warden-line!
83
+
84
+ BUNDLED WITH
85
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # Warden::Line
2
+
3
+ This gem is created for use LINE ID Token as warden strategies to use in LIFF application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'warden-line'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install warden-line
20
+
21
+ ## Usage
22
+
23
+ Currently, the workable version is tested with `rails_warden` gem.
24
+
25
+ ```
26
+ # config/initialize/warden.rb
27
+
28
+ Rails.configuration.middleware.use RailsWarden::Manager do |manager|
29
+ manager.failure_app = proc do |env|
30
+ [
31
+ 401,
32
+ { 'Content-Type' => 'application/json' },
33
+ [{ error: 'Unauthorized', code: 401, reason: env['warden'].message }.to_json]
34
+ ]
35
+ end
36
+ manager.default_strategies :line
37
+ manager.line_client_id = ENV['LINE_CLIENT_ID']
38
+ end
39
+
40
+ # Rails Warden will use `id` to find user, but we want plain hash
41
+ module Warden
42
+ class SessionSerializer
43
+ def serialize(user)
44
+ user
45
+ end
46
+
47
+ def deserialize(key)
48
+ key
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ Create a plain object as model for decoded user.
55
+
56
+ ```ruby
57
+ # app/models/user.rb
58
+
59
+ class User
60
+ include ActiveModel::Model
61
+ include ActiveModel::Attributes
62
+
63
+ attribute :sub, :string
64
+ attribute :exp, :integer
65
+ attribute :name, :string
66
+ attribute :picture, :string
67
+ attribute :email, :string
68
+
69
+ def id
70
+ sub
71
+ end
72
+
73
+ def expired_at
74
+ @expired_at ||= Time.zone.at(exp)
75
+ rescue TypeError
76
+ Time.zone.now
77
+ end
78
+
79
+ def expired?
80
+ Time.zone.now >= expired_at
81
+ end
82
+ end
83
+ ```
84
+
85
+ Implement a controller to handle the session creation for sign-in and sign-out.
86
+
87
+ ```ruby
88
+ # app/controller/sessions.rb
89
+
90
+ class SessionsController < ActionController::Metal
91
+ include Authenticatable
92
+
93
+ def authenticate
94
+ # Ensure clear expired session
95
+ request.env['warden'].logout
96
+ request.env['warden'].authenticate!
97
+
98
+ @user = User.new(request.env['warden'].user.slice(*User.attribute_names))
99
+ # Post login actions
100
+ end
101
+ end
102
+ ```
103
+
104
+ ## Roadmap
105
+
106
+ * [x] Strategy for LINE ID Token
107
+ * [ ] Rails Support
108
+ * [ ] Remove `rails_warden` dependency
109
+ * [ ] Helpers similar to `devise`
110
+ * [ ] User object
111
+
112
+ ## Development
113
+
114
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
115
+
116
+ 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).
117
+
118
+ ## Contributing
119
+
120
+ Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/warden-line. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/elct9620/warden-line/blob/master/CODE_OF_CONDUCT.md).
121
+
122
+
123
+ ## Code of Conduct
124
+
125
+ Everyone interacting in the Warden::Line project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elct9620/warden-line/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'warden/line'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'warden/line/version'
4
+ require 'warden/strategies/line'
5
+
6
+ module Warden
7
+ # Warden Strategies for LINE ID Token
8
+ #
9
+ # @since 0.1.0
10
+ module Line
11
+ end
12
+ end
13
+
14
+ Warden::Config.hash_accessor :line_client_id
15
+ Warden::Strategies.add(:line, Warden::Strategies::Line)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Warden
4
+ module Line
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'warden'
5
+
6
+ module Warden
7
+ module Strategies
8
+ # LINE ID Token Strategies
9
+ #
10
+ # @since 0.1.0
11
+ class Line < Warden::Strategies::Base
12
+ # @since 0.1.0
13
+ VERIFY_TOKEN_URI = URI('https://api.line.me/oauth2/v2.1/verify')
14
+
15
+ # @return [TrueClass|FalseClass]
16
+ #
17
+ # @see Warden::Strategies::Base#valid?
18
+ #
19
+ # @since 0.1.0
20
+ def valid?
21
+ params['id_token'] != nil
22
+ end
23
+
24
+ # @see Warden::Strategies::Base#authenticate!
25
+ #
26
+ # @since 0.1.0
27
+ def authenticate!
28
+ success? ? success!(result) : fail!(result['error_description'])
29
+ end
30
+
31
+ # Token verify result
32
+ #
33
+ # @return [Hash] the verify result
34
+ #
35
+ # @since 0.1.0
36
+ def result
37
+ @result ||= JSON.parse(response.body)
38
+ rescue TypeError, JSON::ParserError
39
+ {}
40
+ end
41
+
42
+ # Token verify success or not
43
+ #
44
+ # @return [TrueClass|FalseClass]
45
+ #
46
+ # @since 0.1.0
47
+ def success?
48
+ response.code.to_i == 200
49
+ end
50
+
51
+ private
52
+
53
+ # @since 0.1.0
54
+ def response
55
+ @response ||= Net::HTTP.post_form(
56
+ VERIFY_TOKEN_URI,
57
+ id_token: params['id_token'],
58
+ client_id: @env['warden'].config[:line_client_id]
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/warden/line/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'warden-line'
7
+ spec.version = Warden::Line::VERSION
8
+ spec.authors = ['蒼時弦也']
9
+ spec.email = ['contact@aotoki.dev']
10
+
11
+ spec.summary = 'The warden strategies for LINE ID Token'
12
+ spec.description = 'The warden strategies for LINE ID Token'
13
+ spec.homepage = 'https://github.com/elct9620/warden-line'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/elct9620/warden-line'
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'warden', '~> 1.0'
29
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warden-line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 蒼時弦也
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: warden
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
+ description: The warden strategies for LINE ID Token
28
+ email:
29
+ - contact@aotoki.dev
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".overcommit.yml"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".travis.yml"
39
+ - CODE_OF_CONDUCT.md
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - lib/warden/line.rb
47
+ - lib/warden/line/version.rb
48
+ - lib/warden/strategies/line.rb
49
+ - warden-line.gemspec
50
+ homepage: https://github.com/elct9620/warden-line
51
+ licenses: []
52
+ metadata:
53
+ homepage_uri: https://github.com/elct9620/warden-line
54
+ source_code_uri: https://github.com/elct9620/warden-line
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.4.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.0.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: The warden strategies for LINE ID Token
74
+ test_files: []