
Untitled
By: a guest on
May 10th, 2012 | syntax:
None | size: 0.81 KB | hits: 30 | expires: Never
Omniauth google oauth2 strategy with offline access
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, KEY, SECRET,
:access_type => 'offline',
:scope => 'https://www.googleapis.com/auth/userinfo.profile'
end
def authorize_params
base_scope_url = "https://www.googleapis.com/auth/"
super.tap do |params|
scopes = (params[:scope] || DEFAULT_SCOPE).split(",")
scopes.map! { |s| s =~ /^https?:/// ? s : "#{base_scope_url}#{s}" }
params[:scope] = scopes.join(' ')
# This makes sure we get a refresh_token.
# http://googlecode.blogspot.com/2011/10/upcoming-changes-to-oauth-20-endpoint.html
**params[:access_type] = 'offline' if params[:access_type].nil?
params[:approval_prompt] = 'force' if params[:approval_prompt].nil?**
end
end