LoginSignup
9
7

More than 5 years have passed since last update.

Qiitaのomniauthを作ってた

Last updated at Posted at 2014-12-17

みんな大好きomniauthのQiitaを作って忘れてました。

omniauth

Railsでソーシャルログインするときにスタンダードになってる方法としてomniauthがあります。
色々な認証の統一的手法を目指しているomniauthですが、なかでもoauth2に対応しているものとしてfacebook等の有名サービスがあります。

QiitaにもOAuth2認証のAPIがあり、omniauthに対応させることができそうですね。

omniauth_qiita

ということで作ったのがこちら
少し前に作ったのですがハッカソン参加してたり意外に忙しかったりで周知してませんでした。

install

いつものとおり

gem 'omniauth_qiita'

auth_hash

{
  :provider => "qiita",
  :uid => "tmiyamon",
  :info => {
    :nickname => "tmiyamon",
    :name => "Takuya Miyamoto",
    :location => "Tokyo, Japan",
    :image => "https://....",
    :description => "An awesome engineer",
    :urls => {
      :Facebook => "https://www.facebook.com/...",
      :Github => "https://github.com/tmiyamon",
      :Twitter => "https://twitter.com/..."
    }
  },
  :credentials => {
    :token => "abc...",
    :expires => false
  },
  :extra => {
    :raw_info => {
      :description => "An awesome engineer",
      :facebook_id => "...",
      :followers_count => 5,
      :followees_count => 0,
      :github_login_name => "tmiyamon",
      :id => "tmiyamon",
      :items_count => 3,
      :linkedin_id => "",
      :location => "Tokyo, Japan",
      :name => "Takuya Miyamoto",
      :organization => "",
      :profile_image_url => "https://...",
      :twitter_screen_name => "...",
      :website_url => "http://tmiyamon.github.io"
    }
  }
}

auth_hashの中身はできるだけomniauthのスキーマに沿うように作ってあります。
first_nameとlast_nameはnameをsplitすることで取れそうですが、片方が空だった場合nameからは判別できなくなるのでinfoには入れてありません。
詳しくはREADME及びsourceをご覧ください。

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7