omniauth-piryx 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16f5d1e16c73fb8382eacd4601e6f41227b99714
4
- data.tar.gz: a74f73bd365dfba0fd3d49bec2249e147b0dcf60
3
+ metadata.gz: f40b804ebbc151265a94ce59e9720a24327ff49e
4
+ data.tar.gz: 660507e61abd2bf592f0e7da1514096611e708c9
5
5
  SHA512:
6
- metadata.gz: ef1cecaa21b50eedaa522c7cf7fb0051278af3d0c27aa6da6d5ed703d0f2e6d740931d140b526a5f6d954c8696693f7542c0166a37b3ac128938602400ba6c11
7
- data.tar.gz: 3f91a5ca390cbf639c8845f5ba609b75a1603b36846e62f3f19ef9b5887ee7c2576368f233c7d417618356d1f4ce25d3578c0369abdd807aa226152e2e19b13f
6
+ metadata.gz: 99f27167d516a7b46020af088b4fb5d4c05053247eba28462124b3a1dfb0a114c95ca7e3a4e777cbd7a8bf2899363f18271e452d35d51785d917be2f428068f5
7
+ data.tar.gz: 2602e02dba5874db2a29a67cdd8dff01c97cd02bc8723da415f62fd7e5d40dbde5a64fb5ddf378652489f5c5def42b12c7026934c1dd95042bc07c8f2d0c8c7b
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+
20
+ /.ruby-version
21
+ /.ruby-gemset
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1
4
+
5
+ Project created and added to github.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Omniauth Automatic Strategy
2
+
3
+ [![Build Status](https://travis-ci.org/SparkartGroupInc/omniauth-google-oauth2.png)](https://travis-ci.org/SparkartGroupInc/omniauth-google-oauth2)
4
+
5
+ [Piryx](http://www.piryx.com) [`omniauth`](http://rubygems.org/gems/omniauth) OAuth2 strategy.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ gem 'omniauth-piryx'
11
+ bundle
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Sign up for Piryx and [create an application](http://www.piryx.com/developers/). Once you have the client id and client secret associate them with the OmniAuth strategy.
17
+
18
+
19
+ ### Example Integration
20
+
21
+ ```ruby
22
+ Rails.application.config.middleware.use OmniAuth::Builder do
23
+ provider :piryx, ENV["PIRYX_CLIENT_ID"], ENV["PIRYX_CLIENT_SECRET"], scope: "never_expire,create_payment,payment_details,payment_summary", sandbox: !Rails.env.production?
24
+ end
25
+ ```
26
+
27
+ If a value for sandbox is not passed in the production API will always be used instead.
28
+
29
+ ### Scopes
30
+
31
+ You can change the permissions by selecting from the [scopes available](http://dev.piryx.com/docs/oauth.html) and passing them into the configuration above. The default scopes set by this middleware are `create_payment` and `payment_details.`
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'piryx')
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'piryx')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Piryx
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Piryx < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = "create_payment,payment_details"
7
+ PRODUCTION_API = 'https://api.piryx.com'
8
+ OLD_PRODUCTION_API = 'https://secure.piryx.com'
9
+ SANDBOX_API = 'https://sandbox-api.piryx.com'
10
+ OLD_SANDBOX_API = 'http://demo.secure.piryx.com'
11
+
12
+ option :name, 'piryx'
13
+
14
+ option :client_options, {
15
+ authorize_url: '/oauth/authorize',
16
+ token_url: '/oauth/access_token'
17
+ }
18
+
19
+ option :authorize_options, [:response_type, :client_id, :redirect_uri, :scope]
20
+
21
+ option :auth_token_params, {
22
+ header_format: "OAuth %s",
23
+ mode: :header,
24
+ param_name: "oauth_token"
25
+ }
26
+
27
+ option :sandbox, false
28
+
29
+ def client
30
+ options.client_options[:site] ||= options.sandbox ? SANDBOX_API : PRODUCTION_API
31
+ ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
32
+ end
33
+
34
+ def authorize_params
35
+ super.tap do |params|
36
+ options.authorize_options.each do |k|
37
+ params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
38
+ end
39
+
40
+ raw_scope = params[:scope] || DEFAULT_SCOPE
41
+ scope_list = raw_scope.split(" ").map {|item| item.split(",")}.flatten
42
+ params[:scope] = scope_list.join(" ")
43
+ end
44
+ end
45
+
46
+ uid { raw_info['Account']['Id'] }
47
+
48
+ info do
49
+ {
50
+ name: raw_info['Account']['Name'],
51
+ biography: raw_info['Account']['Biography'],
52
+ location: raw_info['Account']['Location'],
53
+ website_url: raw_info['Account']['WebsiteUrl']
54
+ }
55
+ end
56
+
57
+ extra do
58
+ hash = {}
59
+ hash[:id_token] = access_token.token
60
+ hash[:raw_info] = raw_info unless skip_info?
61
+ hash
62
+ end
63
+
64
+ def raw_info
65
+ api = options.sandbox ? OLD_SANDBOX_API : OLD_PRODUCTION_API
66
+ @raw_info ||= access_token.get(File.join(api, "api/accounts/me")).parsed
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path(File.join('..', 'lib', 'omniauth', 'piryx', 'version'), __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "omniauth-piryx"
6
+ gem.version = OmniAuth::Piryx::VERSION
7
+ gem.license = 'MIT'
8
+ gem.summary = %q{Piryx OAuth2 strategy for OmniAuth 1.x}
9
+ gem.description = %q{Piryx OAuth2 strategy for OmniAuth 1.x}
10
+ gem.authors = ["Sparkart"]
11
+ gem.email = ["product@sparkart.com"]
12
+ gem.homepage = "https://github.com/SparkartGroupInc/omniauth-piryx"
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 -- {spec}/*`.split("\n")
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_runtime_dependency 'omniauth', '>= 1.1.1'
20
+ gem.add_runtime_dependency 'omniauth-oauth2', '>= 1.1.1'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec', '~> 2.7'
23
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Piryx do
4
+ let(:request) { double('Request', params: {}, cookies: {}, env: {}) }
5
+ let(:app) {
6
+ lambda do
7
+ [200, {}, ["Hello World"]]
8
+ end
9
+ }
10
+
11
+ subject do
12
+ OmniAuth::Strategies::Piryx.new(app, 'appid', 'secret', @options || {}).tap do |strategy|
13
+ allow(strategy).to receive(:request) {
14
+ request
15
+ }
16
+ end
17
+ end
18
+
19
+ before do
20
+ OmniAuth.config.test_mode = true
21
+ end
22
+
23
+ after do
24
+ OmniAuth.config.test_mode = false
25
+ end
26
+
27
+ describe 'client_options' do
28
+ context 'when sandbox is true' do
29
+ before { subject.options[:sandbox] = true }
30
+
31
+ it 'has correct site' do
32
+ expect(subject.client.site).to eq('https://sandbox-api.piryx.com')
33
+ end
34
+ end
35
+
36
+ context 'when sandbox is false' do
37
+ before { subject.options[:sandbox] = false }
38
+
39
+ it 'has correct site' do
40
+ expect(subject.client.site).to eq('https://api.piryx.com')
41
+ end
42
+ end
43
+
44
+ it 'has correct authorize_url' do
45
+ expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
46
+ end
47
+
48
+ it 'has correct token_url' do
49
+ expect(subject.client.options[:token_url]).to eq('/oauth/access_token')
50
+ end
51
+ end
52
+
53
+ describe "authorize_params" do
54
+ it 'should support persist authorized parameters' do
55
+ @options = {
56
+ response_type: "response_type", client_id: "client_id",
57
+ redirect_uri: "redirect_uri", scope: "scope", invalid: "invalid"
58
+ }
59
+
60
+ expect(subject.authorize_params['response_type']).to eq('response_type')
61
+ expect(subject.authorize_params['redirect_uri']).to eq('redirect_uri')
62
+ expect(subject.authorize_params['scope']).to eq('scope')
63
+ expect(subject.authorize_params['invalid']).to eq(nil)
64
+ end
65
+ end
66
+
67
+ describe 'extra' do
68
+ let(:client) do
69
+ OAuth2::Client.new('abc', 'def') do |builder|
70
+ builder.request :url_encoded
71
+ builder.adapter :test do |stub|
72
+ stub.get('/api/accounts/me') do |env|
73
+ [
74
+ 200,
75
+ {'content-type' => 'application/json'},
76
+ '{"Account": {"Name": "George", "Biography": "None", "Location": "Heaven", "WebsiteUrl": "http://www.example.com"}}'
77
+ ]
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }
84
+ before { allow(subject).to receive(:access_token).and_return(access_token) }
85
+
86
+ describe 'info' do
87
+ it 'should populate info' do
88
+ expect(subject.info[:name]).to eq("George")
89
+ expect(subject.info[:biography]).to eq("None")
90
+ expect(subject.info[:location]).to eq("Heaven")
91
+ expect(subject.info[:website_url]).to eq("http://www.example.com")
92
+ end
93
+ end
94
+
95
+ describe 'raw_info' do
96
+ context 'when skip_info is true' do
97
+ before { subject.options[:skip_info] = true }
98
+
99
+ it 'should not include raw_info' do
100
+ expect(subject.extra).not_to have_key(:raw_info)
101
+ end
102
+ end
103
+
104
+ context 'when skip_info is false' do
105
+ before { subject.options[:skip_info] = false }
106
+
107
+ it 'should include raw_info' do
108
+ expect(subject.extra[:raw_info]).to eq({"Account"=>{"Name"=>"George", "Biography"=>"None", "Location"=>"Heaven", "WebsiteUrl"=>"http://www.example.com"}})
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'omniauth-piryx'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-piryx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sparkart
@@ -73,7 +73,19 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".gitignore"
77
+ - CHANGELOG.md
78
+ - Gemfile
76
79
  - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/omniauth-piryx.rb
83
+ - lib/omniauth/piryx.rb
84
+ - lib/omniauth/piryx/version.rb
85
+ - lib/omniauth/strategies/piryx.rb
86
+ - omniauth-piryx.gemspec
87
+ - spec/omniauth/strategies/piryx_spec.rb
88
+ - spec/spec_helper.rb
77
89
  homepage: https://github.com/SparkartGroupInc/omniauth-piryx
78
90
  licenses:
79
91
  - MIT