omniauth-github-1.1.2/0000755000175000017500000000000012325432123014172 5ustar boutilboutilomniauth-github-1.1.2/Gemfile0000644000175000017500000000033612325432123015467 0ustar boutilboutilsource 'http://rubygems.org' # Specify your gem's dependencies in omniauth-github.gemspec gemspec group :development, :test do gem 'guard' gem 'guard-rspec' gem 'guard-bundler' gem 'rb-fsevent' gem 'growl' end omniauth-github-1.1.2/metadata.yml0000644000175000017500000000645612325432123016510 0ustar boutilboutil--- !ruby/object:Gem::Specification name: omniauth-github version: !ruby/object:Gem::Version version: 1.1.2 platform: ruby authors: - Michael Bleigh autorequire: bindir: bin cert_chain: [] date: 2014-04-10 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: omniauth requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: omniauth-oauth2 requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.1' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '1.1' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '2.7' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ~> - !ruby/object:Gem::Version version: '2.7' - !ruby/object:Gem::Dependency name: rack-test requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: simplecov requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: webmock requirement: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' description: Official OmniAuth strategy for GitHub. email: - michael@intridea.com executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .rspec - Gemfile - Guardfile - README.md - Rakefile - lib/omniauth-github.rb - lib/omniauth-github/version.rb - lib/omniauth/strategies/github.rb - omniauth-github.gemspec - spec/omniauth/strategies/github_spec.rb - spec/spec_helper.rb homepage: https://github.com/intridea/omniauth-github licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.3 signing_key: specification_version: 4 summary: Official OmniAuth strategy for GitHub. test_files: [] has_rdoc: omniauth-github-1.1.2/README.md0000644000175000017500000000412012325432123015446 0ustar boutilboutil# OmniAuth GitHub This is the official OmniAuth strategy for authenticating to GitHub. To use it, you'll need to sign up for an OAuth2 Application ID and Secret on the [GitHub Applications Page](https://github.com/settings/applications). ## Basic Usage use OmniAuth::Builder do provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'] end ## Github Enterprise Usage provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], { :client_options => { :site => 'https://github.YOURDOMAIN.com/api/v3', :authorize_url => 'https://github.YOURDOMAIN.com/login/oauth/authorize', :token_url => 'https://github.YOURDOMAIN.com/login/oauth/access_token', } } ## Scopes GitHub API v3 lets you set scopes to provide granular access to different types of data: use OmniAuth::Builder do provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: "user,repo,gist" end More info on [Scopes](http://developer.github.com/v3/oauth/#scopes). ## License Copyright (c) 2011 Michael Bleigh and Intridea, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. omniauth-github-1.1.2/.rspec0000644000175000017500000000001112325432123015277 0ustar boutilboutil--colour omniauth-github-1.1.2/Guardfile0000644000175000017500000000037412325432123016023 0ustar boutilboutilguard '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-github.gemspec') end omniauth-github-1.1.2/Rakefile0000644000175000017500000000022312325432123015634 0ustar boutilboutil#!/usr/bin/env rake require "bundler/gem_tasks" require 'rspec/core/rake_task' RSpec::Core::RakeTask.new desc 'Run specs' task :default => :spec omniauth-github-1.1.2/lib/0000755000175000017500000000000012325432123014740 5ustar boutilboutilomniauth-github-1.1.2/lib/omniauth-github.rb0000644000175000017500000000010712325432123020367 0ustar boutilboutilrequire "omniauth-github/version" require 'omniauth/strategies/github' omniauth-github-1.1.2/lib/omniauth-github/0000755000175000017500000000000012325432123020044 5ustar boutilboutilomniauth-github-1.1.2/lib/omniauth-github/version.rb0000644000175000017500000000010012325432123022045 0ustar boutilboutilmodule OmniAuth module GitHub VERSION = "1.1.2" end end omniauth-github-1.1.2/lib/omniauth/0000755000175000017500000000000012325432123016564 5ustar boutilboutilomniauth-github-1.1.2/lib/omniauth/strategies/0000755000175000017500000000000012325432123020736 5ustar boutilboutilomniauth-github-1.1.2/lib/omniauth/strategies/github.rb0000644000175000017500000000361212325432123022547 0ustar boutilboutilrequire '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 def authorize_params super.tap do |params| %w[scope client_options].each do |v| if request.params[v] params[v.to_sym] = request.params[v] end end end end uid { raw_info['id'].to_s } info do { 'nickname' => raw_info['login'], 'email' => email, 'name' => raw_info['name'], 'image' => raw_info['avatar_url'], 'urls' => { 'GitHub' => "https://github.com/#{raw_info['login']}", 'Blog' => raw_info['blog'], }, } end extra do {:raw_info => raw_info} end def raw_info access_token.options[:mode] = :query @raw_info ||= access_token.get('user').parsed end def email (email_access_allowed?) ? primary_email : raw_info['email'] end def primary_email primary = emails.find{|i| i['primary'] } primary && primary['email'] || emails.first && emails.first['email'] end # The new /user/emails API - http://developer.github.com/v3/users/emails/#future-response def emails return [] unless email_access_allowed? access_token.options[:mode] = :query @emails ||= access_token.get('user/emails', :headers => { 'Accept' => 'application/vnd.github.v3' }).parsed end def email_access_allowed? options['scope'] =~ /user/ end end end end OmniAuth.config.add_camelization 'github', 'GitHub' omniauth-github-1.1.2/spec/0000755000175000017500000000000012325432123015124 5ustar boutilboutilomniauth-github-1.1.2/spec/spec_helper.rb0000644000175000017500000000062512325432123017745 0ustar boutilboutil$:.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-github' RSpec.configure do |config| config.include WebMock::API config.include Rack::Test::Methods config.extend OmniAuth::Test::StrategyMacros, :type => :strategy end omniauth-github-1.1.2/spec/omniauth/0000755000175000017500000000000012325432123016750 5ustar boutilboutilomniauth-github-1.1.2/spec/omniauth/strategies/0000755000175000017500000000000012325432123021122 5ustar boutilboutilomniauth-github-1.1.2/spec/omniauth/strategies/github_spec.rb0000644000175000017500000001073012325432123023744 0ustar boutilboutilrequire 'spec_helper' describe OmniAuth::Strategies::GitHub do let(:access_token) { stub('AccessToken', :options => {}) } let(:parsed_response) { stub('ParsedResponse') } let(:response) { stub('Response', :parsed => parsed_response) } let(:enterprise_site) { 'https://some.other.site.com/api/v3' } let(:enterprise_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' } let(:enterprise_token_url) { 'https://some.other.site.com/login/oauth/access_token' } let(:enterprise) do OmniAuth::Strategies::GitHub.new('GITHUB_KEY', 'GITHUB_SECRET', { :client_options => { :site => enterprise_site, :authorize_url => enterprise_authorize_url, :token_url => enterprise_token_url } } ) end subject do OmniAuth::Strategies::GitHub.new({}) end before(:each) do subject.stub!(:access_token).and_return(access_token) end context "client options" do it 'should have correct site' do subject.options.client_options.site.should eq("https://api.github.com") end it 'should have correct authorize url' do subject.options.client_options.authorize_url.should eq('https://github.com/login/oauth/authorize') end it 'should have correct token url' do subject.options.client_options.token_url.should eq('https://github.com/login/oauth/access_token') end describe "should be overrideable" do it "for site" do enterprise.options.client_options.site.should eq(enterprise_site) end it "for authorize url" do enterprise.options.client_options.authorize_url.should eq(enterprise_authorize_url) end it "for token url" do enterprise.options.client_options.token_url.should eq(enterprise_token_url) end end end context "#email_access_allowed?" do it "should not allow email if scope is nil" do subject.options['scope'].should be_nil subject.should_not be_email_access_allowed end it "should allow email if scope is user" do subject.options['scope'] = 'user' subject.should be_email_access_allowed end it "should allow email if scope is a bunch of stuff including user" do subject.options['scope'] = 'public_repo,user,repo,delete_repo,gist' subject.should be_email_access_allowed end it "should not allow email if scope is other than user" do subject.options['scope'] = 'repo' subject.should_not be_email_access_allowed end it "should assume email access not allowed if scope is something currently not documented " do subject.options['scope'] = 'currently_not_documented' subject.should_not be_email_access_allowed end end context "#email" do it "should return email from raw_info if available" do subject.stub!(:raw_info).and_return({'email' => 'you@example.com'}) subject.email.should eq('you@example.com') end it "should return nil if there is no raw_info and email access is not allowed" do subject.stub!(:raw_info).and_return({}) subject.email.should be_nil end it "should return the primary email if there is no raw_info and email access is allowed" do emails = [ { 'email' => 'secondary@example.com', 'primary' => false }, { 'email' => 'primary@example.com', 'primary' => true } ] subject.stub!(:raw_info).and_return({}) subject.options['scope'] = 'user' subject.stub!(:emails).and_return(emails) subject.email.should eq('primary@example.com') end it "should return the first email if there is no raw_info and email access is allowed" do emails = [ { 'email' => 'first@example.com', 'primary' => false }, { 'email' => 'second@example.com', 'primary' => false } ] subject.stub!(:raw_info).and_return({}) subject.options['scope'] = 'user' subject.stub!(:emails).and_return(emails) subject.email.should eq('first@example.com') end end context "#raw_info" do it "should use relative paths" do access_token.should_receive(:get).with('user').and_return(response) subject.raw_info.should eq(parsed_response) end end context "#emails" do it "should use relative paths" do access_token.should_receive(:get).with('user/emails', :headers=>{"Accept"=>"application/vnd.github.v3"}).and_return(response) subject.options['scope'] = 'user' subject.emails.should eq(parsed_response) end end end omniauth-github-1.1.2/omniauth-github.gemspec0000644000175000017500000000177712325432123020657 0ustar boutilboutil# -*- encoding: utf-8 -*- require File.expand_path('../lib/omniauth-github/version', __FILE__) Gem::Specification.new do |gem| gem.authors = ["Michael Bleigh"] gem.email = ["michael@intridea.com"] gem.description = %q{Official OmniAuth strategy for GitHub.} gem.summary = %q{Official OmniAuth strategy for GitHub.} gem.homepage = "https://github.com/intridea/omniauth-github" 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-github" gem.require_paths = ["lib"] gem.version = OmniAuth::GitHub::VERSION gem.add_dependency 'omniauth', '~> 1.0' gem.add_dependency 'omniauth-oauth2', '~> 1.1' gem.add_development_dependency 'rspec', '~> 2.7' gem.add_development_dependency 'rack-test' gem.add_development_dependency 'simplecov' gem.add_development_dependency 'webmock' end omniauth-github-1.1.2/.gitignore0000644000175000017500000000023312325432123016160 0ustar boutilboutil*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man /pkg rdoc spec/reports test/tmp test/version_tmp tmp omniauth-github-1.1.2/checksums.yaml.gz0000444000175000017500000000041412325432123017457 0ustar boutilboutilGSe=VAE^EoP@Aaff hOGo 5w^n~z|clOƶ-}/oAh]:Wr?9٩u/nKbd ʈj$WMSlD A!jzt?m.J * ٶ^Ңf>6}L qeviTҙKhb] ,^P2zm=Zs`%kSjmOgsmcލ2I/N