omniauth-elance 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
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
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
@@ -0,0 +1,4 @@
1
+ omniauth-elance
2
+ ===============
3
+
4
+ Elance strategy for OmniAuth
@@ -0,0 +1,2 @@
1
+ require "omniauth-elance/version"
2
+ require "omniauth/strategies/elance"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Elance
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Elance < OmniAuth::Strategies::OAuth2
6
+ # Strategy name
7
+ option :name, "elance"
8
+
9
+ # Options being passed to initialize client from the OAuth2 Gem.
10
+ # Note: Elance API's OAuth2 interface uses base uri as:
11
+ # https://api.elance.com/api2 thus passing custom authorize_url and
12
+ # token_url
13
+ option :client_options, {
14
+ site: "https://api.elance.com/api2",
15
+ authorize_url: 'api2/oauth/authorize',
16
+ token_url: 'api2/oauth/token'
17
+ }
18
+
19
+ # Called after authentication has succeeded.
20
+ uid {
21
+ raw_info['userId']
22
+ }
23
+
24
+ info do
25
+ {
26
+ userName: raw_info['userName'],
27
+ name: raw_info['businessName']
28
+ }
29
+ end
30
+
31
+ extra do
32
+ {
33
+ 'raw_info' => raw_info
34
+ }
35
+ end
36
+
37
+ def raw_info
38
+ # Reference: https://www.elance.com/q/api2/methods/profiles/my
39
+ @raw_info ||= access_token.get('/profiles/my?catId=10183')
40
+
41
+ data = @raw_info['data']
42
+ data = data['providerProfile'] if data
43
+ data
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/omniauth-elance/version", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency "omniauth-oauth2", "~> 1.1.1"
6
+
7
+ gem.authors = ["Jignesh Gohel"]
8
+ gem.email = ["jignesh.gohel@botreeconsulting.com"]
9
+ gem.description = %q{Elance strategy for OmniAuth.}
10
+ gem.summary = %q{Elance strategy for OmniAuth.}
11
+ gem.homepage = "https://github.com/JigneshGohel-BoTreeConsulting/omniauth-elance"
12
+ gem.license = "MIT"
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.name = "omniauth-elance"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = OmniAuth::Elance::VERSION
20
+ end
@@ -0,0 +1,52 @@
1
+ # References:
2
+ # http://wiki.openstreetmap.org/wiki/OAuth_ruby_examples
3
+ # https://github.com/intridea/oauth2/blob/master/lib/oauth2/client.rb
4
+ # https://github.com/intridea/omniauth-oauth2/blob/master/lib/omniauth/strategies/oauth2.rb
5
+ # https://github.com/intridea/oauth2/blob/master/lib/oauth2/strategy/auth_code.rb
6
+ # https://github.com/intridea/oauth2/blob/master/lib/oauth2/access_token.rb
7
+ require 'rubygems'
8
+ require 'oauth2'
9
+ require 'date'
10
+ require 'yaml'
11
+
12
+ auth={}
13
+
14
+ puts "First, request for an API key at"
15
+ puts "https://www.elance.com/q/api/request-key"
16
+ puts "Enter the consumer key you are assigned:"
17
+ auth["client_id"] = gets.strip
18
+ puts "Enter the consumer secret you are assigned:"
19
+ auth["client_secret"] = gets.strip
20
+ puts "Your application is now set up, but you need to register"
21
+ puts "this instance of it with your user account."
22
+
23
+ client_opts = {
24
+ site: 'https://api.elance.com',
25
+ authorize_url: 'api2/oauth/authorize',
26
+ token_url: 'api2/oauth/token'
27
+ }
28
+
29
+ @client = OAuth2::Client.new(auth["client_id"], auth["client_secret"], client_opts)
30
+
31
+ puts "Visit the following URL, log in if you need to, and authorize the app"
32
+ authorize_url = @client.auth_code.authorize_url
33
+
34
+ puts authorize_url
35
+
36
+ puts "When you've authorized the request, enter the verifier code you are assigned:"
37
+
38
+ verifier = gets.strip
39
+
40
+ puts "Converting the authorization code into access token..."
41
+
42
+ @access_token= @client.get_token(verifier)
43
+
44
+ auth["token"] = @access_token.token
45
+ auth["token_secret"] = @access_token.secret
46
+
47
+ #File.open('auth.yaml', 'w') { |f| YAML.dump(auth, f) }
48
+
49
+ puts "Done.Following are the credentials to be used to access the API"
50
+ puts "#{auth}"
51
+
52
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-elance
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-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.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.1.1
30
+ description: Elance strategy for OmniAuth.
31
+ email:
32
+ - jignesh.gohel@botreeconsulting.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - README.md
40
+ - lib/omniauth-elance.rb
41
+ - lib/omniauth-elance/version.rb
42
+ - lib/omniauth/strategies/elance.rb
43
+ - omniauth-elance.gemspec
44
+ - scripts/oauth2_elance_test.rb
45
+ homepage: https://github.com/JigneshGohel-BoTreeConsulting/omniauth-elance
46
+ licenses:
47
+ - MIT
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.25
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Elance strategy for OmniAuth.
70
+ test_files: []