Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-20 02:18:09 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-20 02:18:09 +0300
commit6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch)
treedc4d20fe6064752c0bd323187252c77e0a89144b /vendor/gems/omniauth-google-oauth2/examples
parent9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff)
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'vendor/gems/omniauth-google-oauth2/examples')
-rw-r--r--vendor/gems/omniauth-google-oauth2/examples/Gemfile8
-rw-r--r--vendor/gems/omniauth-google-oauth2/examples/config.ru120
-rw-r--r--vendor/gems/omniauth-google-oauth2/examples/omni_auth.rb37
3 files changed, 165 insertions, 0 deletions
diff --git a/vendor/gems/omniauth-google-oauth2/examples/Gemfile b/vendor/gems/omniauth-google-oauth2/examples/Gemfile
new file mode 100644
index 00000000000..ba019344a67
--- /dev/null
+++ b/vendor/gems/omniauth-google-oauth2/examples/Gemfile
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+source 'https://rubygems.org'
+
+gem 'omniauth-google-oauth2', '~> 0.8.1'
+gem 'rubocop'
+gem 'sinatra', '~> 1.4'
+gem 'webrick'
diff --git a/vendor/gems/omniauth-google-oauth2/examples/config.ru b/vendor/gems/omniauth-google-oauth2/examples/config.ru
new file mode 100644
index 00000000000..ee17929094c
--- /dev/null
+++ b/vendor/gems/omniauth-google-oauth2/examples/config.ru
@@ -0,0 +1,120 @@
+# 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
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <title>Google OAuth2 Example</title>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
+ <script>
+ jQuery(function() {
+ return $.ajax({
+ url: 'https://apis.google.com/js/client:plus.js?onload=gpAsyncInit',
+ dataType: 'script',
+ cache: true
+ });
+ });
+
+ window.gpAsyncInit = function() {
+ gapi.auth.authorize({
+ immediate: true,
+ response_type: 'code',
+ cookie_policy: 'single_host_origin',
+ client_id: '#{ENV['GOOGLE_KEY']}',
+ scope: 'email profile'
+ }, function(response) {
+ return;
+ });
+ $('.googleplus-login').click(function(e) {
+ e.preventDefault();
+ gapi.auth.authorize({
+ immediate: false,
+ response_type: 'code',
+ cookie_policy: 'single_host_origin',
+ client_id: '#{ENV['GOOGLE_KEY']}',
+ scope: 'email profile'
+ }, function(response) {
+ if (response && !response.error) {
+ // google authentication succeed, now post data to server.
+ jQuery.ajax({type: 'POST', url: "/auth/google_oauth2/callback", data: response,
+ success: function(data) {
+ // Log the data returning from google.
+ console.log(data)
+ }
+ });
+ } else {
+ // google authentication failed.
+ console.log("FAILED")
+ }
+ });
+ });
+ };
+ </script>
+ </head>
+ <body>
+ <ul>
+ <li><a href='/auth/google_oauth2'>Sign in with Google</a></li>
+ <li><a href='#' class="googleplus-login">Sign in with Google via AJAX</a></li>
+ </ul>
+ </body>
+ </html>
+ 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
diff --git a/vendor/gems/omniauth-google-oauth2/examples/omni_auth.rb b/vendor/gems/omniauth-google-oauth2/examples/omni_auth.rb
new file mode 100644
index 00000000000..0a94164d766
--- /dev/null
+++ b/vendor/gems/omniauth-google-oauth2/examples/omni_auth.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+# Google's OAuth2 docs. Make sure you are familiar with all the options
+# before attempting to configure this gem.
+# https://developers.google.com/accounts/docs/OAuth2Login
+
+Rails.application.config.middleware.use OmniAuth::Builder do
+ # Default usage, this will give you offline access and a refresh token
+ # using default scopes 'email' and 'profile'
+ #
+ provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], scope: 'email,profile'
+
+ # Custom redirect_uri
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], scope: 'email,profile', redirect_uri: 'https://localhost:3000/redirect'
+
+ # Manual setup for offline access with a refresh token.
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], access_type: 'offline'
+
+ # Custom scope supporting youtube. If you are customizing scopes, remember
+ # to include the default scopes 'email' and 'profile'
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], scope: 'http://gdata.youtube.com,email,profile,plus.me'
+
+ # Custom scope for users only using Google for account creation/auth and do not require a refresh token.
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], access_type: 'online', prompt: ''
+
+ # To include information about people in your circles you must include the 'plus.login' scope.
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], skip_friends: false, scope: 'email,profile,plus.login'
+
+ # If you need to acquire whether user picture is a default one or uploaded by user.
+ #
+ # provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], skip_image_info: false
+end