omniauth-bitbucket 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-bitbucket.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-github.gemspec')
10
+ end
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # OmniAuth Bitbucket
2
+
3
+ This is the OmniAuth strategy for authenticating to Bitbucket. To
4
+ use it, you'll need to sign up for an OAuth consumer key and Secret
5
+ by sending emails to [Bitbucket Support](mailto:support@bitbucket.org).
6
+
7
+ ## Basic Usage
8
+
9
+ use OmniAuth::Builder do
10
+ provider :bitbucket, ENV['BITBUCKET_KEY'], ENV['BITBUCKET_SECRET']
11
+ end
12
+
13
+ ## License
14
+
15
+ Copyright (c) 2011 Dingding Ye.
16
+
17
+ 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:
18
+
19
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
20
+
21
+ 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.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run specs'
12
+ task :default => :spec
data/exmaples/test.rb ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'sinatra'
3
+ require 'omniauth'
4
+ require 'omniauth-bitbucket'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'sinatra'
8
+ require 'omniauth'
9
+ require 'omniauth-bitbucket'
10
+ end
11
+
12
+ use Rack::Session::Cookie
13
+ use OmniAuth::Builder do
14
+ provider :bitbucket, ENV['BITBUCKET_KEY'], ENV['BITBUCKET_PAIR']
15
+ end
16
+
17
+ get '/' do
18
+ <<-HTML
19
+ <a href='/auth/bitbucket'>Sign in with Bitbucket</a>
20
+ HTML
21
+ end
22
+
23
+ get '/auth/:name/callback' do
24
+ auth = request.env['omniauth.auth']
25
+ # do whatever you want with the information!
26
+ puts auth.inspect
27
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-bitbucket/version"
2
+ require "omniauth/strategies/bitbucket"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Bitbucket
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'omniauth-oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Bitbucket < OmniAuth::Strategies::OAuth
6
+ # This is where you pass the options you would pass when
7
+ # initializing your consumer from the OAuth gem.
8
+ option :client_options, {
9
+ :site => 'https://bitbucket.org',
10
+ :request_token_path => '/api/1.0/oauth/request_token',
11
+ :authorize_path => '/api/1.0/oauth/authenticate',
12
+ :access_token_path => '/api/1.0/oauth/access_token'
13
+ }
14
+
15
+ # These are called after authentication has succeeded. If
16
+ # possible, you should try to set the UID without making
17
+ # additional calls (if the user id is returned with the token
18
+ # or as a URI parameter). This may not be possible with all
19
+ # providers.
20
+ uid { raw_info['username'] }
21
+
22
+ info do
23
+ {
24
+ :name => "#{raw_info['first_name']} #{raw_info['last_name']}",
25
+ :avatar => raw_info['avatar'],
26
+ :email => raw_info['email']
27
+ }
28
+ end
29
+
30
+ def raw_info
31
+ @raw_info ||= begin
32
+ ri = MultiJson.decode(access_token.get('/api/1.0/user').body)['user']
33
+ email = (MultiJson.decode(access_token.get('/api/1.0/emails').body).find { |email| email['primary'] })['email']
34
+ ri.merge('email' => email) if email
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-bitbucket/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-bitbucket"
7
+ s.version = Omniauth::Bitbucket::VERSION
8
+ s.authors = ["Dingding Ye"]
9
+ s.email = ["yedingding@gmail.com"]
10
+ s.homepage = "https://github.com/sishen/omniauth-bitbucket"
11
+ s.summary = %q{OmniAuth strategy for Bitbucket.}
12
+ s.description = %q{OmniAuth strategy for Bitbucket.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ s.add_dependency 'omniauth', '~> 1.0'
21
+ s.add_dependency 'omniauth-oauth', '~> 1.0'
22
+ s.add_development_dependency 'rspec', '~> 2.7'
23
+ s.add_development_dependency 'rack-test'
24
+ s.add_development_dependency 'simplecov'
25
+ s.add_development_dependency 'webmock'
26
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Bitbucket do
4
+ it 'should do some testing' do
5
+ pending
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-bitbucket'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bitbucket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dingding Ye
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &70224835374860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70224835374860
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth-oauth
27
+ requirement: &70224835367920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70224835367920
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70224835367400 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.7'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70224835367400
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: &70224835366880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70224835366880
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &70224835366260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70224835366260
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: &70224835365380 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70224835365380
80
+ description: OmniAuth strategy for Bitbucket.
81
+ email:
82
+ - yedingding@gmail.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - Guardfile
90
+ - README.md
91
+ - Rakefile
92
+ - exmaples/test.rb
93
+ - lib/omniauth-bitbucket.rb
94
+ - lib/omniauth-bitbucket/version.rb
95
+ - lib/omniauth/strategies/bitbucket.rb
96
+ - omniauth-bitbucket.gemspec
97
+ - spec/omniauth/strategies/bitbucket_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/sishen/omniauth-bitbucket
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.10
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: OmniAuth strategy for Bitbucket.
123
+ test_files:
124
+ - spec/omniauth/strategies/bitbucket_spec.rb
125
+ - spec/spec_helper.rb