Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

UNMAINTAINED -- 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, and to make calls to the FatSecret REST API.


  • Add the gem to your Gemfile:
gem 'fatsecret-omniauth'
  • Run bundle install


  • Add the following to config/initializers/omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :fatsecret, 'consumer_key', 'consumer_secret'

You will need to sign up for a Fatsecret API account. You'll be issued your own consumer_key and consumer_secret, which you should use in the code above.

  • Add your callback route in config/routes.rb:
get '/auth/fatsecret/callback', to: 'YOUR_CONTROLLER#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. Also, you should place your fatsecret-omniauth route above your other OmniAuth routes. Otherwise, your API calls will be routed to sessions#create.

  • FOR EXAMPLE: If you had an ApiTokensController, you could use the following route:

    get '/auth/fatsecret/callback', to: 'api_tokens#create'

To authenticate with FatSecret, and obtain auth tokens:

  • Load /auth/fatsecret in your browser

  • You'll be redirected to 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:

  • Save the auth tokens to make future API calls for user data

API calls

API calls are created with the{}).api_call() method. FatSecret consumer keys and a params hash containing the api call are required. Optionally, you can include an auth_key and auth_secret for authenticated calls.

The structure of an api call looks like this:{}).api_call(

The structure of an authenticated api call looks like this:{}).api_call(

The actual API request data is contained in the params hash. Read the FatSecret REST API method docs and supply the required parameters in the params hash.

NOTE The following required parameters are automatically handled by the gem: oauth_signature_method, oauth_timestamp, oauth_nonce, oauth_version and oauth_signature. Also, since consumer keys are required with every API call, oauth_consumer_key is taken care of as well.

As an example, if you wanted to call the API method, the first thing you would do is look up in the FatSecret API docs and find the required parameters. Aside from the automatic parameters listed above, the only required parameter is method, and it must be set to "".

There are also several optional parameters: format, oauth_token, search_expression, page_number, and max_results. You can include any of these as well. The search_expression would contain the food(s) you're searching for.

If you had an apis_controller with a foods_search method, it might look like this:

class ApisController < ApplicationController
  def foods_search
    params['method'] = ''
    request ={}).api_call(
    @response = request.body

Now you can create a form with a 'search_expression' field that submits to the foods_search method of the ApisController, and the FatSecret API will return your results in @response.

    Assuming the ApisController mentioned above, and the following custom route:

    post '/foods_search', to: 'apis#food_search'

    You could create the form below to allow users to search foods on

<%= form_tag foods_search_path %>
  <%= label_tag(:search_expression, "Search for food:") %>
  <%= text_field_tag(:search_expression) %>
  <%= submit_tag("Search") %>
<% end %> 

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


UNMAINTAINED -- OmniAuth authentication + API wrapper for the OAuth API.







No releases published


No packages published