omniauth-odesk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ Gemfile.lock
8
+ .project
9
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-oauth2.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ omniauth-odesk
2
+ ===============
3
+
4
+ Odesk Developer API OAuth 1.0 Strategy for OmniAuth.
5
+
6
+ Supports the OAuth 1.0 server-side and client-side flows. Read the [Odesk Developer API docs](http://developers.odesk.com/w/page/38106543/Authentication-using-OAuth) for more details.
7
+
8
+ ## Installing
9
+
10
+ Add to your `Gemfile`:
11
+
12
+ ```ruby
13
+ gem 'omniauth-odesk'
14
+ ```
15
+
16
+ Then `bundle install`.
17
+
18
+ ## Usage
19
+
20
+ `OmniAuth::Strategies::Odesk` is simply a Rack middleware.Read the [OmniAuth 1.0](https://github.com/intridea/omniauth) and [OAuth 2.0](https://github.com/intridea/oauth2) docs for detailed instructions
21
+
22
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :elance, ENV['ODESK_CONSUMER_KEY'], ENV['ODESK_CONSUMER_SECRET']
27
+ end
28
+ ```
29
+
30
+ ## Examples
31
+ Standalone usage from a Ruby script samples can be found under `examples` folder.
32
+
33
+ ## Auth Hash
34
+
35
+ Here's an example [Auth Hash](https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema) available in `request.env['omniauth.auth']`:
36
+
37
+ ```ruby
38
+ {
39
+ :provider => 'odesk',
40
+ :uid => '1234567',
41
+ :info => {
42
+ first_name: 'First Name',
43
+ last_name: 'Last Name',
44
+ email: 'email@odesk.com',
45
+ status: 'active',
46
+ profile_key: 'profile_key'
47
+ },
48
+ :credentials => {
49
+ :token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
50
+ :expires_at => 1321747205, # when the access token expires (it always will)
51
+ :expires => true # this will always be true
52
+ },
53
+ :extra => {
54
+ :raw_info => {
55
+ id: "4124672",
56
+ status: "active",
57
+ timezone: "UTC+02:00 Eastern Europe",
58
+ timezone_offset: "10800"
59
+ public_url: 'https://www.odesk.com/users/~~kyad0112d885630b',
60
+ last_name: 'Novozhylov',
61
+ email: 'myemail@odesk.com',
62
+ reference: "12345",
63
+ first_name: "Maksym",
64
+ profile_key: "~~kyad0112d885630b",
65
+ id_provider: '1'
66
+ }
67
+ }
68
+ ```
69
+
70
+ ## License
71
+
72
+ Copyright (c) 2013 by Jignesh Gohel
73
+
74
+ 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:
75
+
76
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77
+
78
+ 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.
@@ -0,0 +1,75 @@
1
+ # References:
2
+ # http://wiki.openstreetmap.org/wiki/OAuth_ruby_examples
3
+ # https://github.com/oauth-xx/oauth-ruby
4
+ # https://github.com/oauth-xx/oauth-ruby/tree/master/lib/oauth
5
+ require 'rubygems'
6
+ require 'oauth'
7
+ require 'json'
8
+
9
+ auth={}
10
+
11
+ puts "First, create API keys at"
12
+ puts "https://www.odesk.com/services/api/keys"
13
+ puts "Enter the consumer key you are assigned:"
14
+ auth[:consumer_key] = gets.strip
15
+ puts "Enter the consumer secret you are assigned:"
16
+ auth[:consumer_secret] = gets.strip
17
+ puts "Your application is now set up, but you need to register"
18
+ puts "this instance of it with your user account."
19
+
20
+ client_opts = {
21
+ site: "https://www.odesk.com",
22
+ request_token_path: "/api/auth/v1/oauth/token/request",
23
+ authorize_path: "/services/api/auth",
24
+ access_token_path: "/api/auth/v1/oauth/token/access"
25
+ }
26
+
27
+ @consumer = OAuth::Consumer.new(auth[:consumer_key], auth[:consumer_secret], client_opts)
28
+ @request_token = @consumer.get_request_token
29
+
30
+ puts "Visit the following URL, log in if you need to, and authorize the app"
31
+ authorize_url = @request_token.authorize_url
32
+
33
+ puts authorize_url
34
+
35
+ puts "When you've authorized the request, enter the verifier code you are assigned:"
36
+
37
+ verifier = gets.strip
38
+
39
+ puts "Converting the authorization code into access token..."
40
+
41
+ access_token_params = {
42
+ oauth_verifier: verifier
43
+ }
44
+
45
+ @access_token= @request_token.get_access_token(access_token_params)
46
+
47
+ auth[:token] = @access_token.token
48
+ auth[:token_secret] = @access_token.secret
49
+
50
+ puts "Done.Following are the credentials to be used to access the API"
51
+ puts "#{auth}"
52
+
53
+ puts "Fetching your basic information now..."
54
+
55
+ raw_info = @access_token.get('/api/hr/v2/users/me.json').read_body
56
+
57
+ if raw_info
58
+ user_info = JSON.parse(raw_info)['user']
59
+ id = user_info['id']
60
+ first_name = user_info['first_name']
61
+ last_name = user_info['last_name']
62
+ email = user_info['email']
63
+ status = user_info['status']
64
+ profile_key = user_info['profile_key']
65
+
66
+ puts "Id: #{id}"
67
+ puts "Name: #{first_name} #{last_name}"
68
+ puts "Email: #{email}"
69
+ puts "Status: #{status}"
70
+ puts "Profile Key: #{profile_key}"
71
+ end
72
+
73
+
74
+
75
+
@@ -0,0 +1,2 @@
1
+ require 'omniauth-odesk/version'
2
+ require 'omniauth/strategies/odesk'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Odesk
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ require 'omniauth-oauth'
2
+ require 'json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Odesk < OmniAuth::Strategies::OAuth
7
+ # Strategy name
8
+ option :name, "odesk"
9
+
10
+ # Options being passed to initialize client from the OAuth Gem.
11
+ # Reference: https://github.com/oauth-xx/oauth-ruby
12
+ option :client_options, {
13
+ site: "https://www.odesk.com",
14
+ request_token_path: "/api/auth/v1/oauth/token/request",
15
+ authorize_path: "/services/api/auth",
16
+ access_token_path: "/api/auth/v1/oauth/token/access"
17
+ }
18
+
19
+ # Called after authentication has succeeded.
20
+ uid {
21
+ raw_info['id']
22
+ }
23
+
24
+ info do
25
+ {
26
+ first_name: raw_info['first_name'],
27
+ last_name: raw_info['last_name'],
28
+ email: raw_info['email'],
29
+ status: raw_info['status'],
30
+ profile_key: raw_info['profile_key']
31
+ }
32
+ end
33
+
34
+ extra do
35
+ {
36
+ 'raw_info' => raw_info
37
+ }
38
+ end
39
+
40
+ def raw_info
41
+ # Reference: https://www.elance.com/q/api2/methods/profiles/my
42
+ raw_info = access_token.get('/api/hr/v2/users/me.json')
43
+
44
+ data = raw_info.read_body
45
+ data = (data ? JSON.parse(data) : {} )
46
+ data['user'] || {}
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-odesk/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth-oauth', '~> 1.0.1'
6
+ gem.add_dependency 'json', '~> 1.8.0'
7
+
8
+ gem.authors = ["Jignesh Gohel"]
9
+ gem.email = ["jignesh.gohel@botreeconsulting.com"]
10
+ gem.description = %q{Odesk strategy for OmniAuth.}
11
+ gem.summary = %q{Odesk strategy for OmniAuth.}
12
+ gem.homepage = "https://github.com/JigneshGohel-BoTreeConsulting/omniauth-odesk"
13
+ gem.license = "MIT"
14
+
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.name = "omniauth-odesk"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = OmniAuth::Odesk::VERSION
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-odesk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jignesh Gohel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.8.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.8.0
46
+ description: Odesk strategy for OmniAuth.
47
+ email:
48
+ - jignesh.gohel@botreeconsulting.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - README.md
56
+ - examples/oauth_odesk_script.rb
57
+ - lib/omniauth-odesk.rb
58
+ - lib/omniauth-odesk/version.rb
59
+ - lib/omniauth/strategies/odesk.rb
60
+ - omniauth-odesk.gemspec
61
+ homepage: https://github.com/JigneshGohel-BoTreeConsulting/omniauth-odesk
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.25
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Odesk strategy for OmniAuth.
86
+ test_files: []