0.0
No commit activity in last 3 years
No release in over 3 years
Beam.pro OAuth2 Strategy for OmniAuth
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
~> 0

Runtime

 Project Readme

Gem Version

OmniAuth::Beam

OmniAuth strategy for Beam.pro

Installation

Add this line to your application's Gemfile:

gem 'omniauth-beam'

Then run bundle install

Or install it yourself with gem install omniauth-beam

Using Directly

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :beam, ENV['BEAM_CLIENT_ID'], ENV['BEAM_SECRET_ID']
end

Using With Devise

Add to config/initializers/devise.rb

  config.omniauth :beam, ENV['BEAM_CLIENT_ID'], ENV['BEAM_SECRET_ID']

And apply it to your Devise user model:

class User < ApplicationRecord
  devise :database_authenticatable, :registerable, :recoverable, :rememberable,
         :trackable, :validatable, :omniauthable,
         omniauth_providers: %i(beam)

  def self.from_omniauth(auth)
    user = where(provider: auth.provider, uid: auth.uid).first_or_create do |u|
      u.password = Devise.friendly_token[0, 20]
      u.provider = auth.provider
      u.uid      = auth.uid
    end
    user.update avatar_url: auth.info.image,
                email:      auth.info.email,
                name:       auth.info.name
    user
  end
end

Default Scope

The default scope is set to user:details:self, making this hash available in request.env['omniauth.auth']:

{
  provider:    'beam',
  uid:         123456789,
  info:        {
    name:        'JohnDoe',
    email:       'johndoe@example.com',
    description: 'My channel.',
    image:       'https://uploads.beam.pro/avatar/12345678-1234.jpg',
    social:      {
      discord:  'johndoe#12345',
      facebook: 'https://facebook.com/John.Doe'
      player:   'https://player.me/johndoe',
      twitter:  'https://twitter.com/johndoe',
      youtube:  'https://youtube.com/user/johndoe'
    },
    urls:        { Beam: 'https://beam.pro/johndoe' }
  },
  credentials: {
    token:         'asdfghjklasdfghjklasdfghjkl',
    refresh_token: 'qwertyuiopqwertyuiopqwertyuiop',
    expires_at:    1477577799,
    expires:       true
  }
}