Giter VIP home page Giter VIP logo

omniauth-smarthr's Introduction

OmniAuth SmartHR

OmniAuth SmartHRはSmartHRとのOAuth連携処理を簡素化するためのOmniAuth strategyです。

インストール

gem 'omniauth-smarthr'

使い方

Rails

OmniAuthをミドルウェアとして登録します。

config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :smarthr, ENV['SMARTHR_CLIENT_ID'], ENV['SMARTHR_CLIENT_SECRET']
end

SMARTHR_CLIENT_ID 及び SMARTHR_CLIENT_SECRETを取得するには SmartHR Plusパートナープログラムについてをご参照の上、お問い合わせください。

環境変数を用意します。

.env:

# Required
SMARTHR_CLIENT_ID=YOUR_CLIENT_ID
SMARTHR_CLIENT_SECRET=YOUR_CLIENT_SECRET

# Optional
# サンドボックス環境を利用する場合には、サンドボックス環境のエンドポイントを指定してください。
SMARTHR_AUTH_ENDPOINT=SANDBOX_ENVIRONMENT_ENDPOINT

ルーティングとコントローラを用意します。

config/routes.rb:

  get 'auth/:provider/callback', to: 'sessions#create'

app/controllers/sessions_controller.rb:

class SessionsController < ApplicationController
  def create
    user_info = request.env['omniauth.auth']
    raise user_info # 適宜セッション管理を行います。
  end
end

ユーザーを/auth/smarthrに遷移させることでOAuth認可コードフローが開始されます。
OAuth認可コードフローが開始するとアプリケーションとの連携許可を求める認可画面が表示されます。
認可画面で連携を許可するとアプリケーションにリダイレクトされSessions#createが呼び出されます。
Sessions#createrequest.env['omniauth.auth']を参照することでSmartHRから受け取ったユーザー情報(アクセストークン含む)を取得できます。

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kufu/omniauth-smarthr.

omniauth-smarthr's People

Contributors

hdyngd avatar tomohiro avatar

Stargazers

CHENG KUN avatar  avatar IZUMIYA Keisuke avatar

Watchers

f440 avatar kurobara avatar K avatar Masato SERIZAWA avatar  avatar yamashu avatar

Forkers

tomohiro

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.