├── lib ├── omniauth-proz.rb └── omniauth │ ├── proz.rb │ ├── proz │ └── version.rb │ └── strategies │ └── proz.rb ├── .rspec ├── .travis.yml ├── spec ├── spec_helper.rb └── omniauth │ └── proz_spec.rb ├── Gemfile ├── Rakefile ├── .gitignore ├── omniauth-proz.gemspec ├── LICENSE.txt └── README.md /lib/omniauth-proz.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth/proz' -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.4 4 | -------------------------------------------------------------------------------- /lib/omniauth/proz.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth/proz/version' 2 | require 'omniauth/strategies/proz' 3 | -------------------------------------------------------------------------------- /lib/omniauth/proz/version.rb: -------------------------------------------------------------------------------- 1 | module Omniauth 2 | module Proz 3 | VERSION = "0.1.17" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'omniauth/proz' 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in omniauth-proz.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | task default: :spec -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /spec/omniauth/proz_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Omniauth::Proz do 4 | it 'has a version number' do 5 | expect(Omniauth::Proz::VERSION).not_to be nil 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /omniauth-proz.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'omniauth/proz/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "omniauth-proz" 8 | spec.version = Omniauth::Proz::VERSION 9 | spec.authors = ["Kevin S. Dias"] 10 | spec.email = ["diasks2@gmail.com"] 11 | 12 | spec.summary = %q{ProZ OAuth2 Strategy for OmniAuth} 13 | spec.description = %q{ProZ.com OAuth2 Strategy for OmniAuth} 14 | spec.homepage = "https://github.com/diasks2/omniauth-proz" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ["lib"] 20 | 21 | spec.add_development_dependency "bundler", "~> 1.9" 22 | spec.add_development_dependency "rake", "~> 10.0" 23 | spec.add_development_dependency "rspec", "3.4.0" 24 | spec.add_runtime_dependency "omniauth-oauth2", "~> 1.2" 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Kevin S. Dias 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OmniAuth Proz 2 | 3 | [ProZ.com](http://www.proz.com/) OAuth2 Strategy for OmniAuth. You can find the ProZ API docs [here](http://www.proz.com/api-docs). 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | ```ruby 10 | gem 'omniauth-proz' 11 | ``` 12 | 13 | And then execute: 14 | 15 | $ bundle 16 | 17 | Or install it yourself as: 18 | 19 | $ gem install omniauth-proz 20 | 21 | ## Usage 22 | 23 | OmniAuth::Strategies::Proz is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth. 24 | 25 | Here's a quick example, adding the middleware to a Rails app with Devise in config/initializers/devise.rb: 26 | 27 | ```ruby 28 | config.omniauth :proz, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], callback_url: '{your-site.com}/users/auth/proz/callback' 29 | ``` 30 | 31 | ## Contributing 32 | 33 | 1. Fork it ( https://github.com/diasks2/omniauth-proz/fork ) 34 | 2. Create your feature branch (`git checkout -b my-new-feature`) 35 | 3. Commit your changes (`git commit -am 'Add some feature'`) 36 | 4. Push to the branch (`git push origin my-new-feature`) 37 | 5. Create a new Pull Request 38 | 39 | ## License 40 | 41 | The MIT License (MIT) 42 | 43 | Copyright (c) 2016 Kevin S. Dias 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining a copy 46 | of this software and associated documentation files (the "Software"), to deal 47 | in the Software without restriction, including without limitation the rights 48 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 49 | copies of the Software, and to permit persons to whom the Software is 50 | furnished to do so, subject to the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be included in 53 | all copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 56 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 60 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 61 | THE SOFTWARE. 62 | -------------------------------------------------------------------------------- /lib/omniauth/strategies/proz.rb: -------------------------------------------------------------------------------- 1 | require 'omniauth-oauth2' 2 | 3 | module OmniAuth 4 | module Strategies 5 | class Proz < OmniAuth::Strategies::OAuth2 6 | 7 | DEFAULT_SCOPE = 'user.email wiwo media.post' 8 | 9 | option :name, :proz 10 | 11 | option :client_options, { 12 | :site => 'https://www.proz.com', 13 | :authorize_url => '/oauth/authorize', 14 | :token_url => '/oauth/token' 15 | } 16 | 17 | option :authorize_options, [:scope] 18 | 19 | uid { raw_info['uuid'] } 20 | 21 | info do 22 | { 23 | :email => raw_info["email"], 24 | :name => raw_info["site_name"], 25 | :profile_url => raw_info["profile_url"], 26 | :contact_info => { 27 | :email => raw_info["contact_info"]["email"], 28 | :first_name => raw_info["contact_info"]["first_name"], 29 | :middle_name => raw_info["contact_info"]["middle_name"], 30 | :last_name => raw_info["contact_info"]["last_name"] 31 | }, 32 | :proz_membership => { 33 | :status => raw_info["proz_membership"]["status"], 34 | :expiration_date => raw_info["proz_membership"]["expiration_date"], 35 | :expired_date => raw_info["proz_membership"]["expired_date"], 36 | :certified_pro_network_status => raw_info["proz_membership"]["certified_pro_network_status"] 37 | } 38 | } 39 | end 40 | 41 | def raw_info 42 | @raw_info ||= access_token.get('https://api.proz.com/v2/user').parsed 43 | end 44 | 45 | def authorize_params 46 | super.tap do |params| 47 | %w[scope].each do |v| 48 | if request.params[v] 49 | params[v.to_sym] = request.params[v] 50 | end 51 | end 52 | 53 | params[:scope] ||= DEFAULT_SCOPE 54 | end 55 | end 56 | 57 | protected 58 | 59 | def build_access_token 60 | params = { 61 | 'client_id' => client.id, 62 | 'client_secret' => client.secret, 63 | 'code' => request.params['code'], 64 | 'grant_type' => 'authorization_code', 65 | 'redirect_uri' => options[:callback_url] 66 | }.merge(token_params.to_hash(symbolize_keys: true)) 67 | client.get_token(params, deep_symbolize(options.auth_token_params)) 68 | end 69 | 70 | end 71 | end 72 | end --------------------------------------------------------------------------------