omniauth-instagram-graph 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/omniauth-instagram-graph.rb +1 -0
- data/lib/omniauth/instagram-graph.rb +2 -0
- data/lib/omniauth/instagram-graph/long_lived_client.rb +23 -0
- data/lib/omniauth/instagram-graph/long_lived_token.rb +20 -0
- data/lib/omniauth/instagram-graph/version.rb +5 -0
- data/lib/omniauth/strategies/instagram-graph.rb +110 -0
- data/omniauth-instagram-graph.gemspec +28 -0
- data/test/helper.rb +56 -0
- data/test/strategy_test.rb +23 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d4011d4a572fe34b44b58ba89b23562a979ce122695e6c6eccd82c3d0417fb46
|
4
|
+
data.tar.gz: 4ca610d7d5888a79e766e334a3aa7a2dc49d13b6606a4e5b68cc1aa22d7fc318
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89e02390e96974525d79f5804bd6b9c035ca4988d360e8bfb04f773fbb70108cc96c5e23b85dfd8a64c862b5d22ac6a5d8109ee058dc1715108276b37f44e2f4
|
7
|
+
data.tar.gz: 4f015b1ef8e9f78a3d5aba5f21feca4ab7233bc1c67e4d5c37a49143aebcd8a5b72ca5e72becfe499cfd735fb94ea6b8f59dedd77d792df06642ebae05e4901d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at igor.alexandrov@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-instagram-graph (1.0.0)
|
5
|
+
omniauth (~> 1.9)
|
6
|
+
omniauth-oauth2 (~> 1.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.3)
|
12
|
+
faraday (1.0.0)
|
13
|
+
multipart-post (>= 1.2, < 3)
|
14
|
+
hashie (3.6.0)
|
15
|
+
jwt (2.2.1)
|
16
|
+
minitest (5.14.0)
|
17
|
+
mocha (1.11.2)
|
18
|
+
multi_json (1.14.1)
|
19
|
+
multi_xml (0.6.0)
|
20
|
+
multipart-post (2.1.1)
|
21
|
+
oauth2 (1.4.4)
|
22
|
+
faraday (>= 0.8, < 2.0)
|
23
|
+
jwt (>= 1.0, < 3.0)
|
24
|
+
multi_json (~> 1.3)
|
25
|
+
multi_xml (~> 0.5)
|
26
|
+
rack (>= 1.2, < 3)
|
27
|
+
omniauth (1.9.0)
|
28
|
+
hashie (>= 3.4.6, < 3.7.0)
|
29
|
+
rack (>= 1.6.2, < 3)
|
30
|
+
omniauth-oauth2 (1.6.0)
|
31
|
+
oauth2 (~> 1.1)
|
32
|
+
omniauth (~> 1.9)
|
33
|
+
rack (2.2.2)
|
34
|
+
rake (12.3.3)
|
35
|
+
rspec (3.9.0)
|
36
|
+
rspec-core (~> 3.9.0)
|
37
|
+
rspec-expectations (~> 3.9.0)
|
38
|
+
rspec-mocks (~> 3.9.0)
|
39
|
+
rspec-core (3.9.1)
|
40
|
+
rspec-support (~> 3.9.1)
|
41
|
+
rspec-expectations (3.9.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.9.0)
|
44
|
+
rspec-mocks (3.9.1)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.9.0)
|
47
|
+
rspec-support (3.9.2)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
minitest
|
54
|
+
mocha
|
55
|
+
omniauth-instagram-graph!
|
56
|
+
rake (~> 12.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
2.1.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Igor Alexandrov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# OmniAuth Instagram Graph [![Build Status](https://secure.travis-ci.org/jetrockets/omniauth-instagram-graph.svg?branch=master)](https://travis-ci.org/jetrockets/omniauth-instagram-graph) [![Gem Version](https://img.shields.io/gem/v/omniauth-instagram-graph.svg)](https://rubygems.org/gems/omniauth-instagram-graph)
|
2
|
+
|
3
|
+
Instagram OAuth2 Strategy for OmniAuth.
|
4
|
+
|
5
|
+
Supports OAuth 2.0 server-side flow with new Instagram Basic Display API and Long Live Tokens. Read the Instagram docs for more details: https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions
|
6
|
+
|
7
|
+
Inspired by [OmniAuth Strategy for Facebook](https://github.com/simi/omniauth-facebook).
|
8
|
+
|
9
|
+
## Installing
|
10
|
+
|
11
|
+
Add to your `Gemfile`:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'omniauth-instagram-graph'
|
15
|
+
```
|
16
|
+
|
17
|
+
Then `bundle install`.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
`OmniAuth::Strategies::InstagramGraph` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
|
22
|
+
|
23
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
27
|
+
provider :instagram_graph, ENV['INSTAGRAM_APP_ID'], ENV['INSTAGRAM_APP_SECRET']
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuring
|
32
|
+
|
33
|
+
You can configure several options, which you pass in to the `provider` method via a `Hash`:
|
34
|
+
|
35
|
+
| Option name | Default | Description |
|
36
|
+
|-------------------------------------|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
37
|
+
| `scope` | `'user_profile,user_media'` | A comma-separated list of permissions you want to request from the user. |
|
38
|
+
| `info_fields` | `'account_type,id,media_count,username'` | A comma-separated list of fields should be returned when getting the user's info (see more https://developers.facebook.com/docs/instagram-basic-display-api/reference/user). |
|
39
|
+
| `callback_url` | | Specify a custom callback URL used during the server-side flow. Note this must be allowed by your app configuration on Facebook (see 'Valid OAuth redirect URIs' under the 'Basic Display' settings section in the configuration for your Facebook app for more details). |
|
40
|
+
| `exchange_access_token_to_long_lived` | `true` | Should `access_token` be exchanged to a Long-Lived token during callback phase of OmniAuth (see more about Long-Lived tokens here: https://developers.facebook.com/docs/instagram-basic-display-api/guides/long-lived-access-tokens) |
|
41
|
+
|
42
|
+
|
43
|
+
## Auth Hash
|
44
|
+
|
45
|
+
Here's an example Auth Hash available in `request.env['omniauth.auth']`:
|
46
|
+
|
47
|
+
```
|
48
|
+
{
|
49
|
+
provider: 'instagram_graph',
|
50
|
+
uid: '1234567',
|
51
|
+
info: {
|
52
|
+
name: 'igor_alexandrov',
|
53
|
+
nickname 'igor_alexandrov'
|
54
|
+
},
|
55
|
+
credentials: {
|
56
|
+
token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
|
57
|
+
expires_at: 1321747205, # when the access token expires (it always will)
|
58
|
+
expires: true # this will always be true
|
59
|
+
},
|
60
|
+
extra: {
|
61
|
+
raw_info: {
|
62
|
+
account_type: 'PERSONAL',
|
63
|
+
id: '17841400519842852',
|
64
|
+
media_count: 211,
|
65
|
+
username: "igor_alexandrov"
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
## Long-Lived Tokens
|
72
|
+
|
73
|
+
Long-Lived Tokens are valid for 60 days. To be able to use token after, you need to refresh it. Here is a sample code, that will help.
|
74
|
+
|
75
|
+
|
76
|
+
``` ruby
|
77
|
+
client = Omniauth::InstagramGraph::LongLivedClient.new(ENV['INSTAGRAM_APP_ID'], ENV['INSTAGRAM_APP_SECRET'])
|
78
|
+
token = client.get_token(access_token: "<CURRENT LONG-LIVED TOKEN>")
|
79
|
+
refreshed = token.refresh
|
80
|
+
```
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
Everyone interacting in the Omniauth::Instagram::Graph project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/omniauth-instagram-graph/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "omniauth/instagram/graph"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/instagram-graph'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Omniauth
|
2
|
+
module InstagramGraph
|
3
|
+
class LongLivedClient < OAuth2::Client
|
4
|
+
TOKEN_URL = '/access_token'
|
5
|
+
|
6
|
+
def initialize(client_id, client_secret, options = {})
|
7
|
+
options = {
|
8
|
+
site: "https://graph.instagram.com",
|
9
|
+
authorize_url: nil,
|
10
|
+
token_url: TOKEN_URL,
|
11
|
+
token_method: :get
|
12
|
+
}.merge!(options)
|
13
|
+
|
14
|
+
super(client_id, client_secret, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_token(params = {})
|
18
|
+
params = { grant_type: 'ig_exchange_token', client_secret: secret }.merge!(params)
|
19
|
+
super(params, {}, LongLivedToken)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Omniauth
|
2
|
+
module InstagramGraph
|
3
|
+
class LongLivedToken < OAuth2::AccessToken
|
4
|
+
TOKEN_REFRESH_PATH = '/refresh_access_token'
|
5
|
+
|
6
|
+
|
7
|
+
def refresh(params = {})
|
8
|
+
options = {
|
9
|
+
token_url: TOKEN_REFRESH_PATH
|
10
|
+
}
|
11
|
+
refresh_client = Omniauth::InstagramGraph::LongLivedClient.new(client.id, client.secret, options)
|
12
|
+
|
13
|
+
params[:grant_type] = 'ig_refresh_token'
|
14
|
+
params[:access_token] = token
|
15
|
+
|
16
|
+
refresh_client.get_token(params)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
require 'omniauth/instagram-graph/long_lived_token'
|
3
|
+
require 'omniauth/instagram-graph/long_lived_client'
|
4
|
+
require 'openssl'
|
5
|
+
require 'rack/utils'
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
module OmniAuth
|
9
|
+
module Strategies
|
10
|
+
class InstagramGraph < OmniAuth::Strategies::OAuth2
|
11
|
+
class NoAuthorizationCodeError < StandardError; end
|
12
|
+
|
13
|
+
DEFAULT_SCOPE = 'user_profile,user_media'
|
14
|
+
USER_INFO_URL = 'https://graph.instagram.com/me'
|
15
|
+
|
16
|
+
option :name, 'instagram_graph'
|
17
|
+
|
18
|
+
option :client_options, {
|
19
|
+
site: 'https://api.instagram.com',
|
20
|
+
authorize_url: "https://api.instagram.com/oauth/authorize",
|
21
|
+
token_url: 'oauth/access_token'
|
22
|
+
}
|
23
|
+
|
24
|
+
option :exchange_access_token_to_long_lived, true
|
25
|
+
|
26
|
+
option :authorize_options, [:scope, :display, :auth_type]
|
27
|
+
|
28
|
+
uid { raw_info['id'] }
|
29
|
+
|
30
|
+
info do
|
31
|
+
prune!({
|
32
|
+
'nickname' => raw_info['username'],
|
33
|
+
'name' => raw_info['username'],
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
extra do
|
38
|
+
hash = {}
|
39
|
+
hash['raw_info'] = raw_info unless skip_info?
|
40
|
+
prune! hash
|
41
|
+
end
|
42
|
+
|
43
|
+
def raw_info
|
44
|
+
@raw_info ||= access_token.get(USER_INFO_URL, info_options).parsed || {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def info_options
|
48
|
+
params = {}
|
49
|
+
params.merge!({fields: (options[:info_fields] || 'account_type,id,media_count,username')})
|
50
|
+
|
51
|
+
{ params: params }
|
52
|
+
end
|
53
|
+
|
54
|
+
def callback_url
|
55
|
+
options[:callback_url] || (full_host + script_name + callback_path)
|
56
|
+
end
|
57
|
+
|
58
|
+
# You can pass +scope+ param to the auth request, if you need to set them dynamically.
|
59
|
+
# You can also set these options in the OmniAuth config :authorize_params option.
|
60
|
+
def authorize_params
|
61
|
+
super.tap do |params|
|
62
|
+
%w[scope].each do |v|
|
63
|
+
if request.params[v]
|
64
|
+
params[v.to_sym] = request.params[v]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
params[:scope] ||= DEFAULT_SCOPE
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def callback_phase # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
|
73
|
+
error = request.params["error_reason"] || request.params["error"]
|
74
|
+
if error
|
75
|
+
fail!(error, CallbackError.new(request.params["error"], request.params["error_description"] || request.params["error_reason"], request.params["error_uri"]))
|
76
|
+
elsif !options.provider_ignores_state && (request.params["state"].to_s.empty? || request.params["state"] != session.delete("omniauth.state"))
|
77
|
+
fail!(:csrf_detected, CallbackError.new(:csrf_detected, "CSRF detected"))
|
78
|
+
else
|
79
|
+
self.access_token = build_access_token
|
80
|
+
|
81
|
+
if options.exchange_access_token_to_long_lived
|
82
|
+
self.access_token = long_lived_client.get_token(access_token: access_token.token)
|
83
|
+
end
|
84
|
+
|
85
|
+
super
|
86
|
+
end
|
87
|
+
rescue ::OAuth2::Error, CallbackError => e
|
88
|
+
fail!(:invalid_credentials, e)
|
89
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
90
|
+
fail!(:timeout, e)
|
91
|
+
rescue ::SocketError => e
|
92
|
+
fail!(:failed_to_connect, e)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def long_lived_client
|
99
|
+
Omniauth::InstagramGraph::LongLivedClient.new(client.id, client.secret)
|
100
|
+
end
|
101
|
+
|
102
|
+
def prune!(hash)
|
103
|
+
hash.delete_if do |_, value|
|
104
|
+
prune!(value) if value.is_a?(Hash)
|
105
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/omniauth/instagram-graph/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "omniauth-instagram-graph"
|
5
|
+
spec.version = Omniauth::InstagramGraph::VERSION
|
6
|
+
spec.authors = ["Igor Alexandrov"]
|
7
|
+
spec.email = ["igor.alexandrov@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = "instagram Graph OAuth2 Strategy for OmniAuth"
|
10
|
+
spec.homepage = "http://github.com/jetrockets/omniauth-instagram-graph"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "http://github.com/jetrockets/omniauth-instagram-graph"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'omniauth', '~> 1.9'
|
23
|
+
spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'minitest'
|
26
|
+
spec.add_development_dependency 'mocha'
|
27
|
+
spec.add_development_dependency 'rake'
|
28
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'mocha/setup'
|
5
|
+
require 'omniauth/strategies/instagram-graph'
|
6
|
+
|
7
|
+
OmniAuth.config.test_mode = true
|
8
|
+
|
9
|
+
module BlockTestHelper
|
10
|
+
def test(name, &blk)
|
11
|
+
method_name = "test_#{name.gsub(/\s+/, '_')}"
|
12
|
+
raise "Method already defined: #{method_name}" if instance_methods.include?(method_name.to_sym)
|
13
|
+
define_method method_name, &blk
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module CustomAssertions
|
18
|
+
def assert_has_key(key, hash, msg = nil)
|
19
|
+
msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
|
20
|
+
assert hash.has_key?(key), msg
|
21
|
+
end
|
22
|
+
|
23
|
+
def refute_has_key(key, hash, msg = nil)
|
24
|
+
msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
|
25
|
+
refute hash.has_key?(key), msg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class TestCase < Minitest::Test
|
30
|
+
extend BlockTestHelper
|
31
|
+
include CustomAssertions
|
32
|
+
end
|
33
|
+
|
34
|
+
class StrategyTestCase < TestCase
|
35
|
+
def setup
|
36
|
+
@request = stub('Request')
|
37
|
+
@request.stubs(:params).returns({})
|
38
|
+
@request.stubs(:cookies).returns({})
|
39
|
+
@request.stubs(:env).returns({})
|
40
|
+
@request.stubs(:scheme).returns({})
|
41
|
+
@request.stubs(:ssl?).returns(false)
|
42
|
+
|
43
|
+
@client_id = '123'
|
44
|
+
@client_secret = '53cr3tz'
|
45
|
+
@options = {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def strategy
|
49
|
+
@strategy ||= begin
|
50
|
+
args = [@client_id, @client_secret, @options].compact
|
51
|
+
OmniAuth::Strategies::InstagramGraph.new(nil, *args).tap do |strategy|
|
52
|
+
strategy.stubs(:request).returns(@request)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'omniauth-instagram-graph'
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
class StrategyTest < StrategyTestCase
|
7
|
+
# include OAuth2StrategyTests
|
8
|
+
end
|
9
|
+
|
10
|
+
class ClientTest < StrategyTestCase
|
11
|
+
test 'has correct Instagram site' do
|
12
|
+
assert_equal 'https://api.instagram.com', strategy.client.site
|
13
|
+
end
|
14
|
+
|
15
|
+
test 'has correct authorize url' do
|
16
|
+
assert_equal 'https://api.instagram.com/oauth/authorize', strategy.client.options[:authorize_url]
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'has correct token url' do
|
20
|
+
assert_equal 'oauth/access_token', strategy.client.options[:token_url]
|
21
|
+
assert_equal 'https://api.instagram.com/oauth/access_token', strategy.client.token_url
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-instagram-graph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Alexandrov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- igor.alexandrov@gmail.com
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- setup
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/omniauth-instagram-graph.rb
|
103
|
+
- lib/omniauth/instagram-graph.rb
|
104
|
+
- lib/omniauth/instagram-graph/long_lived_client.rb
|
105
|
+
- lib/omniauth/instagram-graph/long_lived_token.rb
|
106
|
+
- lib/omniauth/instagram-graph/version.rb
|
107
|
+
- lib/omniauth/strategies/instagram-graph.rb
|
108
|
+
- omniauth-instagram-graph.gemspec
|
109
|
+
- test/helper.rb
|
110
|
+
- test/strategy_test.rb
|
111
|
+
homepage: http://github.com/jetrockets/omniauth-instagram-graph
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata:
|
115
|
+
homepage_uri: http://github.com/jetrockets/omniauth-instagram-graph
|
116
|
+
source_code_uri: http://github.com/jetrockets/omniauth-instagram-graph
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 2.3.0
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.0.6
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: instagram Graph OAuth2 Strategy for OmniAuth
|
136
|
+
test_files:
|
137
|
+
- test/helper.rb
|
138
|
+
- test/strategy_test.rb
|