Coder Social home page Coder Social logo

omniauth-feishu's Introduction

OmniAuth Feishu

Strategy to authenticate with Feishu via OAuth2 in OmniAuth.

Gem Version Build Status

Installation

Add this line to your application's Gemfile:

gem 'omniauth-feishu'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install omniauth-feishu

Before You Begin

You should have already created your app in feishu platform, if not, go to https://open.feishu.cn/app/ to create one.

Take note of your App Id and App Secret because that is what your web application will use to authenticate against the Feishu API. Make sure to set a redirect URL or else you may get authentication error.

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 :feishu, 'App ID', 'App Secret'
end

Devise Usage

Adapted from Devise OmniAuth Instructions

# app/models/user.rb
class User < ApplicationRecord
  #...
  devise :omniauthable, omniauth_providers: %i[feishu]
  #...
end

# config/initializers/devise.rb
config.omniauth :feishu, 'App ID', 'App Secret'

# Below controller assumes callback route configuration following 
# in config/routes.rb
Devise.setup do |config|
  # ...
  devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
end

# app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def feishu
    @user = User.from_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      sign_in_and_redirect @user, event: :authentication
    else
      session["devise.feishu"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    flash[:alert] = request.env["omniauth.error"]
    redirect_to root_path
  end
end

Devise will create the following url methods:

  • user_feishu_omniauth_authorize_path
  • user_feishu_omniauth_callback_path

So you may add a button like this:

<%= link_to "Sign in with feishu", user_feishu_omniauth_authorize_path, class: "btn" %>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/renny-ren/omniauth-feishu.

License

The gem is available as open source under the terms of the MIT License.

omniauth-feishu's People

Contributors

icyleaf avatar nowa avatar renny-ren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

omniauth-feishu's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.