Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Omniauth google oauth2 strategy with offline access
  2. Rails.application.config.middleware.use OmniAuth::Builder do
  3.   provider :google_oauth2, KEY, SECRET,
  4.   :access_type => 'offline',
  5.   :scope => 'https://www.googleapis.com/auth/userinfo.profile'
  6. end
  7.        
  8. def authorize_params
  9.     base_scope_url = "https://www.googleapis.com/auth/"
  10.     super.tap do |params|
  11.       scopes = (params[:scope] || DEFAULT_SCOPE).split(",")
  12.       scopes.map! { |s| s =~ /^https?:/// ? s : "#{base_scope_url}#{s}" }
  13.       params[:scope] = scopes.join(' ')
  14.       # This makes sure we get a refresh_token.
  15.       # http://googlecode.blogspot.com/2011/10/upcoming-changes-to-oauth-20-endpoint.html
  16.       **params[:access_type] = 'offline' if params[:access_type].nil?
  17.       params[:approval_prompt] = 'force' if params[:approval_prompt].nil?**
  18.     end
  19.   end