0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
An omniauth provider to connect to Tapjoy
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

omniauth-tapjoy

Build Status

This is an omniauth plugin that can be used to connect to Tapjoy.

Installation

Add this line to your application's Gemfile:

gem 'omniauth-tapjoy'

And then execute:

$ bundle

Create config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :tapjoy, TAPJOY_KEY, TAPJOY_SECRET
end

Now when you hit the /auth/tapjoy on your server, it will redirect to oauth.tapjoy.com then back to /auth/tapjoy/callback with credentials. We will now setup this callback route

Add this line to config/routes.rb:

match '/auth/tapjoy/callback' => 'user_sessions#create'

Create the app/controllers/user_sessions_controller.rb

class UserSessionsController < ApplicationController
  def create
    # This likely needs more logic to do things such as creating new users
    user = User.find(request.env['omniauth.auth']['uid'])
    session[:user_id] = user.id # or however you log a user in
  end
end

Installation with Devise

If you are using Devise, this is how you can use Tapjoy as your OAUTH provider.

Add this line to your application's Gemfile:

gem 'omniauth-tapjoy'

And then execute:

$ bundle

Add this line to config/intializers/devise.rb:

config.omniauth :tapjoy, 'TAPJOY_KEY', 'TAPJOY_SECRET'

Add a callback controller to be run after the user is authenticated: app/controllers/users/omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def tapjoy
    user = request.env["omniauth.auth"]["info"]
    @user = User.find_or_initialize_by_email(user["email"].downcase)
    @user.first_name = user["first_name"]
    @user.last_name = user["last_name"]
    @user.save!

    flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: "Tapjoy"
    sign_in_and_redirect @user, :event => :authentication
    finished('sign_up_text')
  end
end

Set the route to use the callback you just created:

devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }

Environment settings passed in at application start will always be respected, but if you wish to automatically use the staging environment in development, you may add the following lines to your config/environments/development.rb

ENV['TAPJOY_AUTH_ENV'] ||= "staging"
OmniAuth::Strategies::Tapjoy.reconfigure

If you aren't using Devise, you can either connect to the oauth server directly, or directly use omniauth: https://github.com/intridea/omniauth

Information available

{
  "id": "63be812b-706d-44c9-9e47-742511c6f939",
  "email": "jeff@tapjoy.com",
  "first_name": "Jeff",
  "last_name": "Dickey",
  "created_at": "2012-02-08T05:36:09Z",
  "facebook_id": "42004440",
  "country": "United States",
  "time_zone": "Pacific Time (US & Canada)",
  "is_employee": true
}

Example

For an example of this in use, check the wheeler board: https://github.com/Tapjoy/wheeler_board