# frozen_string_literal: true
# Sample app for Google OAuth2 Strategy
# Make sure to setup the ENV variables GOOGLE_KEY and GOOGLE_SECRET
# Run with "bundle exec rackup"
require 'rubygems'
require 'bundler'
require 'sinatra'
require 'omniauth'
require 'omniauth-google-oauth2'
# Do not use for production code.
# This is only to make setup easier when running through the sample.
#
# If you do have issues with certs in production code, this could help:
# http://railsapps.github.io/openssl-certificate-verify-failed.html
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
# Main example app for omniauth-google-oauth2
class App < Sinatra::Base
get '/' do
<<-HTML
Google OAuth2 Example
HTML
end
post '/auth/:provider/callback' do
content_type 'text/plain'
begin
request.env['omniauth.auth'].to_hash.inspect
rescue StandardError
'No Data'
end
end
get '/auth/:provider/callback' do
content_type 'text/plain'
begin
request.env['omniauth.auth'].to_hash.inspect
rescue StandardError
'No Data'
end
end
get '/auth/failure' do
content_type 'text/plain'
begin
request.env['omniauth.auth'].to_hash.inspect
rescue StandardError
'No Data'
end
end
end
use Rack::Session::Cookie, secret: ENV['RACK_COOKIE_SECRET']
use OmniAuth::Builder do
# For additional provider examples please look at 'omni_auth.rb'
# The key provider_ignores_state is only for AJAX flows. It is not recommended for normal logins.
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], access_type: 'offline', prompt: 'consent', provider_ignores_state: true, scope: 'email,profile,calendar'
end
run App.new