0.0
No commit activity in last 3 years
No release in over 3 years
A rails plugin handling login stuff in controller
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

~> 4.0.10
 Project Readme

WARNING:

This gem is renamed to whoru and no longer maintained. Please refer to the new place for updated codes.

TokenPostman

A Rails plugin handling login stuff in Controller

Installation

add gem 'token_postman' in the Gemfile and then $ bundle install

Usage

in users_controller.rb

class UsersController < ApplicationController
  include TokenPostman
  login FacebookUser, :with => :facebook_login
end

in config/routes.rb

post '/fb_login' => 'users#facebook_login'

In a nutshell:

After the setup above, the /fb_login api would take

{
  "account": "the-account",
  "validator": "the-validator"
}
  • 200: When success, returns user.as_json
  • 409: When login failed, returns 409
  • 400: Returns 400 if miss parameters

App Login:

Append access_token onto response.

Web Login:

TokenPostman does web login if params[:cookie] exists. When web login, TokenPostman appends access_token on cookies['TOKEN_POSTMAN'], instead of appending it on response.

How it works:

Take the setup above as an example:

TokenPostman create a method facebook_login on the fly. In the created method, TokenPostman takes params[:account] and params[:validator] and pass them into FacebookUser::login(account, validator), which should return a user.

TokenPostman then invokes user#generate_access_token(user#generate_web_access_token for web login) and appends it on response / cookies. It would raise TokenPostman::MethodNotImplementedException if any one of FacebookUser::login, FacebookUser#generate_access_token, FacebookUser#generate_web_access_token is not implemented.

Model Requirement

  • UserClass::login(account, validator): should return a user if account and valiator are matched, return nil if not.

  • UserClass#generate_access_token: should return an access token used by app login

  • UserClass#generate_web_access_token: should return an access for web login

Licence:

MIT