Skip to content

Commit

Permalink
add clients
Browse files Browse the repository at this point in the history
  • Loading branch information
goya committed Mar 16, 2017
1 parent 4ad5b9a commit 387b353
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source 'http://rubygems.org'

# Specify your gem's dependencies in omniauth-clients.gemspec
gemspec

group :development, :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
gem 'rb-fsevent'
gem 'growl'
end
10 changes: 10 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end

guard 'bundler' do
watch('Gemfile')
watch('omniauth-clients.gemspec')
end
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# OmniAuth AdobeId

This is the OmniAuth strategies for all clients authenticating for phonegapbuild.

## Basic Usage

use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
end
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rspec/core/rake_task'

desc 'Default: run specs.'
task :default => :spec

desc "Run specs"
RSpec::Core::RakeTask.new

desc 'Run specs'
task :default => :spec
4 changes: 4 additions & 0 deletions lib/omniauth-clients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'omniauth/strategies/adobeid'
require 'omniauth/strategies/github'
require 'omniauth/strategies/bitbucket'
require 'omniauth/strategies/gitlab'
5 changes: 5 additions & 0 deletions lib/omniauth-clients/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OmniAuth
module Clients
VERSION = "0.9"
end
end
37 changes: 37 additions & 0 deletions lib/omniauth/strategies/adobeid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class AdobeId < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://ims-na1.adobelogin.com/ims/profile/v1',
:authorize_url => 'https://ims-na1.adobelogin.com/ims/authorize/v1',
:token_url => 'https://ims-na1.adobelogin.com/ims/token/v1'
}
option :provider_ignores_state, true

def request_phase
options[:authorize_params].merge!(:locale => I18n.locale)
super
end

uid { raw_info['userId'] }

info do
{
'nickname' => raw_info['email'],
'email' => raw_info['email'],
'name' => raw_info['name'],
'service_accounts' => raw_info['serviceAccounts'],
'country_code' => raw_info['countryCode']
}
end

def raw_info
@raw_info ||= access_token.get('').parsed
end
end
end
end

OmniAuth.config.add_camelization 'adobeid', 'AdobeId'
36 changes: 36 additions & 0 deletions lib/omniauth/strategies/bitbucket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class BitBucket < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://bitbucket.org',
:authorize_url => '/site/oauth2/authorize',
:token_url => '/site/oauth2/access_token'
}

uid { raw_info['uuid'] }

def callback_url
nil
end

info do
{
'nickname' => raw_info['username'],
'name' => raw_info['display_name']
}
end

def raw_info
access_token.options[:mode] = :query
if @raw_info.nil?
@raw_info = (access_token.get('/api/2.0/user').parsed)
end
return @raw_info
end
end
end
end

OmniAuth.config.add_camelization 'bitbucket', 'BitBucket'
38 changes: 38 additions & 0 deletions lib/omniauth/strategies/github.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class GitHub < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://api.github.com',
:authorize_url => 'https://github.com/login/oauth/authorize',
:token_url => 'https://github.com/login/oauth/access_token'
}

def request_phase
super
end

uid { raw_info['id'] }

info do
{
'nickname' => raw_info['login'],
'email' => raw_info['email'],
'name' => raw_info['name']
}
end

def raw_info
access_token.options[:mode] = :query
if @raw_info.nil?
@raw_info = access_token.get('/user').parsed
@raw_info['email'] = access_token.get('/user/emails').parsed
end
return @raw_info
end
end
end
end

OmniAuth.config.add_camelization 'github', 'GitHub'
42 changes: 42 additions & 0 deletions lib/omniauth/strategies/gitlab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class GitLab < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://gitlab.com',
:authorize_url => '/oauth/authorize',
:token_url => '/oauth/token'
}

option :redirect_url

uid { raw_info['id'].to_s }

def callback_url
nil
end

info do
{
'nickname' => raw_info['username'],
'name' => raw_info['display_name'],
'email' => raw_info['email']
}
end

def raw_info
@raw_info ||= access_token.get('/api/v3/user').parsed
end

private

def callback_url
options.redirect_url || (full_host + script_name + callback_path)
end

end
end
end

OmniAuth.config.add_camelization 'gitlab', 'GitLab'
24 changes: 24 additions & 0 deletions omniauth-clients.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/omniauth-clients/version', __FILE__)

Gem::Specification.new do |gem|
gem.authors = ["Brett Rudd"]
gem.email = ["rudd@adobe.com"]
gem.description = %q{OmniAuth clients for PhoneGapBuild.}
gem.summary = %q{OmniAuth clients for PhoneGapBuild.}
gem.homepage = "https://github.com/nitobi/omniauth-clients"

gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.name = "omniauth-clients"
gem.require_paths = ["lib"]
gem.version = OmniAuth::Clients::VERSION

gem.add_dependency 'omniauth'
gem.add_dependency 'omniauth-oauth2'
gem.add_development_dependency 'rspec', '~> 2.7'
gem.add_development_dependency 'rack-test'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'webmock'
end
7 changes: 7 additions & 0 deletions spec/omniauth/strategies/adobeid_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe OmniAuth::Strategies::AdobeId do
it 'should do some testing' do
pending
end
end
9 changes: 9 additions & 0 deletions spec/omniauth/strategies/github_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe OmniAuth::Strategies::GitHub do
it 'should do some testing' do
pending
end
end


16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require 'simplecov'
SimpleCov.start
require 'rspec'
require 'rack/test'
require 'webmock/rspec'
require 'omniauth'
require 'omniauth-clients'

RSpec.configure do |config|
config.include WebMock::API
config.include Rack::Test::Methods
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
end

0 comments on commit 387b353

Please sign in to comment.