oauth_token_verifier 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +45 -0
- data/.travis.yml +14 -3
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +61 -0
- data/CONTRIBUTING.md +26 -0
- data/README.md +94 -16
- data/lib/oauth_token_verifier/configuration.rb +9 -9
- data/lib/oauth_token_verifier/providers/facebook.rb +39 -37
- data/lib/oauth_token_verifier/providers/google.rb +37 -35
- data/lib/oauth_token_verifier/providers/vk.rb +40 -37
- data/lib/oauth_token_verifier/version.rb +1 -1
- data/oauth_token_verifier.gemspec +2 -3
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c9354ca786fb7678c32477020f6957561457639
|
4
|
+
data.tar.gz: 94c29354f7ff28eb2cb5086e97f34c9aca82141a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dd5ba7c7fd9c47404366e85bc1eddfe60395af9db2c97e57e07a027d8983afd6a26901301af44c2fea23519e1ea31bdd97a47e045bb2cee4ddfd83d381e55e1
|
7
|
+
data.tar.gz: 1d50eb2330d884ef0377a8669db98b3573b3953354aba4fc43a7e0c3fc2d216a5a23b9c6b5f31cc93e3f139969e57250100a452cb55f13d1b0a6a7bf18643da7
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Offense count: 1
|
2
|
+
# Configuration parameters: AllowSafeAssignment.
|
3
|
+
Lint/AssignmentInCondition:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
# Offense count: 2
|
7
|
+
Lint/HandleExceptions:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Offense count: 1
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 20
|
13
|
+
|
14
|
+
# Offense count: 84
|
15
|
+
# Configuration parameters: AllowURI, URISchemes.
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
# Offense count: 1
|
20
|
+
# Configuration parameters: CountComments.
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 21
|
23
|
+
|
24
|
+
# Offense count: 6
|
25
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
26
|
+
Style/ClassAndModuleChildren:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
# Offense count: 19
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
AllCops:
|
34
|
+
TargetRubyVersion: 2.2
|
35
|
+
Exclude:
|
36
|
+
- bin/**/*
|
37
|
+
- config/**/*
|
38
|
+
- db/**/*
|
39
|
+
- vendor/**/*
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- Guardfile
|
43
|
+
|
44
|
+
Rails:
|
45
|
+
Enabled: true
|
data/.travis.yml
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
matrix:
|
4
|
+
fast_finish: true
|
5
|
+
include:
|
6
|
+
- rvm: ruby-head
|
7
|
+
- rvm: jruby-9.1.0.0
|
8
|
+
- rvm: 2.5.0
|
9
|
+
- rvm: 2.4.1
|
10
|
+
- rvm: 2.3.1
|
11
|
+
- rvm: 2.2.0
|
12
|
+
allow_failures:
|
13
|
+
- rvm: ruby-head
|
14
|
+
- rvm: jruby-9.1.0.0
|
15
|
+
|
16
|
+
before_install: gem install bundler -v 1.16.0
|
6
17
|
install: bundle install --jobs=3 --retry=3
|
7
18
|
script:
|
8
19
|
- bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
Changelog
|
2
2
|
============
|
3
3
|
|
4
|
+
#### 0.1.5
|
5
|
+
- added version parameter reflecting recent vk.com API changes
|
6
|
+
|
7
|
+
#### 0.1.4
|
8
|
+
- minor fixes, travis integration added
|
9
|
+
|
10
|
+
#### 0.1.3
|
11
|
+
- Remove activesupport specifics
|
12
|
+
|
4
13
|
#### 0.1.2
|
5
14
|
- Explicitly require net/http
|
6
15
|
|
16
|
+
#### 0.1.1
|
17
|
+
- Basic API interaction logic
|
18
|
+
|
7
19
|
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
## 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
|
+
### Attribution
|
56
|
+
|
57
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
58
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
59
|
+
|
60
|
+
[homepage]: http://contributor-covenant.org
|
61
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
### Reporting issues
|
2
|
+
|
3
|
+
Please, provide further explanations to your issue:
|
4
|
+
|
5
|
+
- Expected behaviour
|
6
|
+
|
7
|
+
- Actual behaviour
|
8
|
+
|
9
|
+
- Steps to reproduce
|
10
|
+
|
11
|
+
Make sure to include as much information as possible. It's even better if you include test, showin failing scenario,
|
12
|
+
or all-in-one script to make easier to reproduce the bug.
|
13
|
+
|
14
|
+
### Submitting a pull request
|
15
|
+
|
16
|
+
Key points when submitting a pull request:
|
17
|
+
|
18
|
+
- Add tests
|
19
|
+
|
20
|
+
- Update documentation
|
21
|
+
|
22
|
+
- Make all changes in feature branch, i.e. `feature/tg_integration`
|
23
|
+
|
24
|
+
- Make one pull request for each feature, don't include all in one pull request
|
25
|
+
|
26
|
+
- Maintain sensible commit history
|
data/README.md
CHANGED
@@ -1,68 +1,146 @@
|
|
1
|
+
# OauthTokenVerifier
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/oauth_token_verifier.svg)](https://badge.fury.io/rb/oauth_token_verifier)
|
1
4
|
[![Build Status](https://travis-ci.org/Shkrt/oauth_token_verifier.svg?branch=master)](https://travis-ci.org/Shkrt/oauth_token_verifier)
|
5
|
+
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7458de9e473f4a7188f8b17cdf8806b8)](https://www.codacy.com/app/zxcgpppmnn/oauth_token_verifier?utm_source=github.com&utm_medium=referral&utm_content=Shkrt/oauth_token_verifier&utm_campaign=Badge_Grade)
|
2
6
|
|
3
|
-
|
7
|
+
## Motivation
|
8
|
+
|
9
|
+
This library's only responsibility is to verify oauth2 access tokens that have been obtained from third party.
|
10
|
+
No access tokens needed.
|
11
|
+
|
12
|
+
Real-world use case:
|
4
13
|
|
5
|
-
|
14
|
+
- You have a mobile application, with users authenticating via oauth2 providers.
|
15
|
+
|
16
|
+
With the help of this library you can use oauth2 access tokens to validate the token, verify the user identity and map users' attributes to the custom attributes.
|
6
17
|
|
7
18
|
Example of oauth2 flow using this library is shown below:
|
8
19
|
|
9
20
|
![alt text](https://github.com/Shkrt/oauth_token_verifier/raw/master/oauth2_flow.png "Flow example")
|
10
21
|
|
22
|
+
The depicted workflow consists of the following steps:
|
23
|
+
|
24
|
+
1. User clicks OAuth login button at the mobile application interface
|
25
|
+
|
26
|
+
2. User is being shown an authorization dialogue from OAuth provider, where he/she approves permissions to access account data
|
27
|
+
|
28
|
+
3. Mobile application receives an access token from OAuth2 provider and immediately passes it to backend app
|
29
|
+
|
30
|
+
4. Backend application receives the token and makes a request to the OAuth provider
|
31
|
+
|
32
|
+
5. Backend application receives info from OAuth provider and does something with it - authenticates the user, creates the user, updates user's data.
|
33
|
+
|
11
34
|
## Installation
|
12
35
|
|
13
36
|
install manually:
|
14
37
|
|
15
|
-
|
38
|
+
```shell
|
39
|
+
gem install oauth_token_verifier
|
40
|
+
```
|
16
41
|
|
17
|
-
or using
|
42
|
+
or using Bundler:
|
18
43
|
|
19
|
-
|
44
|
+
```ruby
|
45
|
+
# Gemfile
|
46
|
+
|
47
|
+
gem 'oauth_token_verifier'
|
48
|
+
```
|
20
49
|
|
21
50
|
## Configuration
|
22
51
|
|
23
|
-
```
|
52
|
+
```ruby
|
24
53
|
OauthTokenVerifier.configure do |c|
|
25
54
|
...
|
26
55
|
end
|
27
56
|
```
|
28
57
|
|
58
|
+
##### Enabled providers
|
59
|
+
|
29
60
|
You should configure enabled providers first, only three providers are supported by now
|
30
61
|
|
31
|
-
```
|
62
|
+
```ruby
|
32
63
|
c.enabled_providers = [:google, :facebook, :vk]
|
33
64
|
```
|
34
65
|
|
35
|
-
|
66
|
+
If you try to use the provider that is not in `enabled_providers` list, the `NoProviderFoundError` will be raised.
|
36
67
|
|
37
|
-
|
68
|
+
Then goes separate configuration for each provider
|
69
|
+
|
70
|
+
##### name
|
71
|
+
|
72
|
+
Name, that will be returned in the resulting Struct. Basically, it's just a custom alias for provider. Each provider
|
73
|
+
will be given the default name if no alias provided.
|
74
|
+
|
75
|
+
```ruby
|
38
76
|
# provider name to be returned
|
39
|
-
c.facebook.name = '
|
77
|
+
c.facebook.name = 'fb'
|
40
78
|
```
|
41
79
|
|
42
|
-
|
80
|
+
##### id_field
|
81
|
+
|
82
|
+
Id field from OAuth provider response, that will be used as unique id. The default values are `email` for `Google`,
|
83
|
+
`id` for `Facebook` and `uid` for `Vk`.
|
84
|
+
|
85
|
+
```ruby
|
43
86
|
# id field - this used to uniquely identify user
|
44
87
|
c.facebook.id_field = 'id'
|
45
88
|
```
|
89
|
+
##### fields_mapping
|
46
90
|
|
47
|
-
|
91
|
+
Mapping of other returned fields to arbitrary field names.
|
92
|
+
By default, no fields parameter passed when querying a provider. With this setting configured, the query parameter will
|
93
|
+
contain the additional parameters to query more information from OAuth provider.
|
94
|
+
Feel free to add any field supported by the chosen provider, but keeo in mind that not all the fields are available to
|
95
|
+
query without api tokens.
|
48
96
|
|
49
|
-
```
|
97
|
+
```ruby
|
50
98
|
c.facebook.fields_mapping = { first_name: :name }
|
51
99
|
|
52
100
|
c.vk.name = 'vkontakte'
|
53
101
|
c.vk.id_field = 'uid'
|
102
|
+
|
103
|
+
# here we map vk's sex field to gender, and photo_id field to avatar
|
54
104
|
c.vk.fields_mapping = { sex: :gender, photo_id: :avatar }
|
55
105
|
|
56
106
|
c.google.name = 'google'
|
57
107
|
c.google.id_field = 'email'
|
58
108
|
c.google.fields_mapping = { given_name: :first_name, picture: :avatar }
|
109
|
+
```
|
110
|
+
|
111
|
+
##### version
|
112
|
+
|
113
|
+
Version is a required parameter for VK provider. Default VK API version 3.0 is deprecated so it is
|
114
|
+
neccessary to pass `v` parameter explicitly for any API call to VK. Recommended API version is 5.0+.
|
115
|
+
Version `5.0` is configured in gem by default, but it's possible to override it:
|
59
116
|
|
117
|
+
```ruby
|
118
|
+
c.vk.version = '5.73'
|
60
119
|
```
|
61
120
|
|
121
|
+
|
62
122
|
## Usage
|
63
123
|
|
64
|
-
|
124
|
+
```ruby
|
125
|
+
include OauthTokenVerifier
|
126
|
+
```
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
verify(:google, token: 'some_very_long_unreadable_sequence_here')
|
130
|
+
|
131
|
+
```
|
65
132
|
|
66
|
-
|
133
|
+
The response will either return a struct, containing profile info fields, or raise an exception with error explanation:
|
67
134
|
|
68
|
-
|
135
|
+
```ruby
|
136
|
+
=> #<struct OauthTokenVerifier::Providers::Vk::BaseFields
|
137
|
+
uid=00010101010,
|
138
|
+
provider="vk",
|
139
|
+
info=#<struct first_name="John", last_name="Smith">>
|
140
|
+
```
|
141
|
+
|
142
|
+
Example of error response:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
OauthTokenVerifier::TokenVerifier::TokenCheckError: Invalid Value
|
146
|
+
```
|
@@ -1,24 +1,24 @@
|
|
1
1
|
module OauthTokenVerifier
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :enabled_providers, :google, :vk, :facebook
|
4
|
-
ProviderSettings = Struct.new(:fields_mapping, :name, :id_field)
|
4
|
+
ProviderSettings = Struct.new(:fields_mapping, :name, :id_field, :version)
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@enabled_providers = []
|
8
8
|
|
9
9
|
@google = ProviderSettings.new({
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
first_name: :given_name,
|
11
|
+
last_name: :family_name
|
12
|
+
}, 'google', 'email')
|
13
13
|
|
14
14
|
@vk = ProviderSettings.new({
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
first_name: :first_name,
|
16
|
+
last_name: :last_name
|
17
|
+
}, 'vk', 'uid', '5.0')
|
18
18
|
|
19
19
|
@facebook = ProviderSettings.new({
|
20
|
-
|
21
|
-
|
20
|
+
first_name: :name
|
21
|
+
}, 'facebook', 'id')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,50 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module OauthTokenVerifier
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module OauthTokenVerifier
|
4
|
+
module Providers
|
5
|
+
class Facebook
|
6
|
+
BaseFields = Struct.new(:uid, :provider, :info)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@data_fields = Struct.new(*config.fields_mapping.values)
|
10
|
+
@request_fields = config.fields_mapping.keys.join(',')
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def verify_token(context)
|
14
|
+
uri = build_uri(context.token)
|
15
|
+
response = check_response(uri)
|
16
|
+
parse_response(response)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
+
private
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def config
|
22
|
+
OauthTokenVerifier.configuration.facebook
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def build_uri(token)
|
26
|
+
params = { access_token: token, fields: @request_fields }
|
27
|
+
URI::HTTPS.build(host: 'graph.facebook.com',
|
28
|
+
path: '/me',
|
29
|
+
query: URI.encode_www_form(params))
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def check_response(uri)
|
33
|
+
response = JSON.parse(Net::HTTP.get(uri))
|
34
|
+
if error = response['error']
|
35
|
+
raise OauthTokenVerifier::TokenVerifier::TokenCheckError, error['message']
|
36
|
+
else
|
37
|
+
response
|
38
|
+
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def parse_response(data)
|
42
|
+
BaseFields.new(
|
43
|
+
data[config.id_field],
|
44
|
+
config.name,
|
45
|
+
@data_fields.new(
|
46
|
+
*data.values_at(*config.fields_mapping.keys.map(&:to_s))
|
47
|
+
)
|
46
48
|
)
|
47
|
-
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
@@ -1,49 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module OauthTokenVerifier
|
4
|
-
|
5
|
-
|
3
|
+
module OauthTokenVerifier
|
4
|
+
module Providers
|
5
|
+
class Google
|
6
|
+
BaseFields = Struct.new(:uid, :provider, :info)
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize
|
9
|
+
@data_fields = Struct.new(*config.fields_mapping.values)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def verify_token(context)
|
13
|
+
uri = build_uri(context.token)
|
14
|
+
response = check_response(uri)
|
15
|
+
parse_response(response)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
+
private
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def config
|
21
|
+
OauthTokenVerifier.configuration.google
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def build_uri(token)
|
25
|
+
params = { id_token: token }
|
26
|
+
URI::HTTPS.build(host: 'www.googleapis.com',
|
27
|
+
path: '/oauth2/v3/tokeninfo',
|
28
|
+
query: URI.encode_www_form(params))
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def check_response(uri)
|
32
|
+
response = JSON.parse(Net::HTTP.get(uri))
|
33
|
+
if error = response['error_description']
|
34
|
+
raise OauthTokenVerifier::TokenVerifier::TokenCheckError, error
|
35
|
+
else
|
36
|
+
response
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def parse_response(data)
|
41
|
+
BaseFields.new(
|
42
|
+
data[config.id_field],
|
43
|
+
config.name,
|
44
|
+
@data_fields.new(
|
45
|
+
*data.values_at(*config.fields_mapping.keys.map(&:to_s))
|
46
|
+
)
|
45
47
|
)
|
46
|
-
|
48
|
+
end
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
@@ -1,50 +1,53 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module OauthTokenVerifier
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module OauthTokenVerifier
|
4
|
+
module Providers
|
5
|
+
class Vk
|
6
|
+
BaseFields = Struct.new(:uid, :provider, :info)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@data_fields = Struct.new(*config.fields_mapping.values)
|
10
|
+
@request_fields = config.fields_mapping.keys.join(',')
|
11
|
+
@version = config.version
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def verify_token(context)
|
15
|
+
uri = build_uri(context.token)
|
16
|
+
response = check_response(uri)
|
17
|
+
parse_response(response)
|
18
|
+
end
|
17
19
|
|
18
|
-
|
20
|
+
private
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
def config
|
23
|
+
OauthTokenVerifier.configuration.vk
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def build_uri(token)
|
27
|
+
params = { access_token: token, fields: @request_fields, v: @version }
|
28
|
+
URI::HTTPS.build(host: 'api.vk.com',
|
29
|
+
path: '/method/users.get',
|
30
|
+
query: URI.encode_www_form(params))
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def check_response(uri)
|
34
|
+
response = JSON.parse(Net::HTTP.get(uri))
|
35
|
+
if error = response['error']
|
36
|
+
raise OauthTokenVerifier::TokenVerifier::TokenCheckError, error['error_msg']
|
37
|
+
else
|
38
|
+
response['response'].first
|
39
|
+
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
def parse_response(data)
|
43
|
+
BaseFields.new(
|
44
|
+
data[config.id_field],
|
45
|
+
config.name,
|
46
|
+
@data_fields.new(
|
47
|
+
*data.values_at(*config.fields_mapping.keys.map(&:to_s))
|
48
|
+
)
|
46
49
|
)
|
47
|
-
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
lib = File.expand_path('../lib', __FILE__)
|
4
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
3
|
require 'oauth_token_verifier/version'
|
@@ -12,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
12
10
|
|
13
11
|
spec.summary = 'Oauth2 token verification'
|
14
12
|
spec.description = 'This library provides possibility of verifying oauth2 access tokens obtained from third party'
|
15
|
-
spec.homepage =
|
13
|
+
spec.homepage = 'https://github.com/Shkrt/oauth_token_verifier'
|
16
14
|
spec.license = 'MIT'
|
17
15
|
|
18
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -23,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
23
21
|
spec.require_paths = ['lib']
|
24
22
|
|
25
23
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
24
|
+
spec.add_development_dependency 'byebug'
|
26
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
27
|
spec.add_development_dependency 'webmock'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_token_verifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shkrt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,8 +90,11 @@ extra_rdoc_files: []
|
|
76
90
|
files:
|
77
91
|
- ".gitignore"
|
78
92
|
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
79
94
|
- ".travis.yml"
|
80
95
|
- CHANGELOG.md
|
96
|
+
- CODE_OF_CONDUCT.md
|
97
|
+
- CONTRIBUTING.md
|
81
98
|
- Gemfile
|
82
99
|
- LICENSE.txt
|
83
100
|
- README.md
|