0.0
No commit activity in last 3 years
No release in over 3 years
The warden strategies for LINE ID Token
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.0
 Project Readme

Warden::Line

Build Status Maintainability Test Coverage

This gem is created for use LINE ID Token as warden strategies to use in LIFF application.

Installation

Add this line to your application's Gemfile:

gem 'warden-line'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install warden-line

Usage

Currently, the workable version is tested with Rails.

# config/initialize/warden.rb

Rails.configuration.middleware.use Warden::Manager do |manager|
  manager.failure_app = proc do |env|
    Rails.logger.error(env['warden'].message)
    [
      401,
      { 'Content-Type' => 'application/json' },
      [{ error: 'Unauthorized', code: 401, reason: env['warden'].message }.to_json]
    ]
  end
  manager.default_strategies :line
  manager.line_client_id = ENV['LINE_CLIENT_ID']
end

Create a plain object as model for decoded user.

# app/models/user.rb

class User
  include ActiveModel::Model
  include ActiveModel::Attributes

  attribute :sub, :string
  attribute :exp, :integer
  attribute :name, :string
  attribute :picture, :string
  attribute :email, :string

  def id
    sub
  end

  def expired_at
    @expired_at ||= Time.zone.at(exp)
  rescue TypeError
    Time.zone.now
  end

  def expired?
    Time.zone.now >= expired_at
  end
end

Implement a controller to handle the session creation for sign-in and sign-out.

# app/controller/sessions.rb

class SessionsController < ActionController::Metal
  include Authenticatable

  def authenticate
    # Ensure clear expired session
    request.env['warden'].logout
    request.env['warden'].authenticate!

    @user = User.new(request.env['warden'].user.slice(*User.attribute_names))
    # Post login actions
  end
end

Note: The Rack does not parse JSON body, please use GET with query string or POST with HTML Form to authenticate.

Roadmap

  • Strategy for LINE ID Token
  • Rails Support
    • Remove rails_warden dependency
    • Helpers similar to devise
  • User object

Development

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.

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.

Contributing

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.

Code of Conduct

Everyone interacting in the Warden::Line project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.