No commit activity in last 3 years
No release in over 3 years
饿了么商家平台 OAuth2.0 对接开发
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0

Runtime

 Project Readme

Omniauth-eleme-oauth2

Eleme OAuth2 Strategy for OmniAuth 1.0.

You need to get a eleme API key at: https://open.shop.ele.me/

Eleme oauth2 specification can be found at: https://open.shop.ele.me/openapi/documents/oauth

Installation

Add to your Gemfile:

gem "omniauth-eleme-oauth2"

Then bundle install.

Usage

Here's an example for adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :eleme, ENV["ELEME_KEY"], ENV["ELEME_SECRET"]
end

You can now access the OmniAuth Eleme OAuth2 URL: /auth/eleme

Configuration

You can configure several options, which you pass in to the provider method via a hash:

For devise user, you can set up scope in your devise.rb as following.

config.omniauth :eleme, ENV["ELEME_KEY"], ENV["ELEME_SECRET"]

Auth Hash

Here's an example of an authentication hash available in the callback by accessing request.env["omniauth.auth"]:

{
    :provider => "eleme",
    :info => {
      token_type: "bearer"
    },
    :credentials => {
        :token => "access_token",
        :refresh_token => "refresh_token",
        :expires_in => 7200,
        :expires => true
    },
    :extra => {}
}

Also, you may need params from redirect_uri. e.g. if you access http://localhost:3000/auth/eleme?branch_id=25. Here's an example of an parameter hash available in the callback by accessing request.env["omniauth.params"].:

{
  branch_id: 25
}

If you have any question about this gem, please contact me by email (xie_s@isumeng.com) or wechat(微信号:wanxsb)