FatSecret OmniAuth Gem v0.0.2

First things first - This is NOT an OmniAuth Strategy. This is not meant to be used as a Login method for web apps. This gem leverages OmniAuth's OAuth Strategy to obtain auth tokens and auth secrets for use with the FatSecret REST API.


Installing

Add the strategy to your Gemfile:

gem 'fatsecret-omniauth'

Then run bundle install


Authentication

This works like any other OmniAuth strategy. Add the following to config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :fatsecret, 'consumer_key', 'consumer_secret'
end

Add your callback route in config/routes.rb:

get '/auth/fatsecret/callback', to: 'YOUR_CREATE_METHOD'

NOTE: OmniAuth strategies use get '/auth/:provider/callback', to: 'sessions#create'. The FatSecret OmniAuth gem requires a custom controller/create method to save the auth tokens in a database for future API calls.

To authenticate wuth FatSsecret

  • load /auth/fatsecret
  • You'll be redirected to FatSecret.com to authenticate
  • If you agree to authenticate, you'll be redirected back /auth/fatsecret/callback
  • The request.env['omniauth.auth'] hash will contain your FatSecret data.

    • FatSecret profile data is contained in:
      request.env['omniauth.auth']['info'] -- see the FatSecret profile.get page for more details.
    • FatSecret auth token and auth secret are contained in:
      request.env['omniauth.auth']['credentials']

Copyright (c) 2013 Scott McGrath. See LICENSE for details.