oauth2_fb_exchange_token_strategy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c6bfe2cf444e601dd3d7c0f52bd0aa4d6c35b2c8706c6839f89e42c794b2ef1
4
+ data.tar.gz: b8da9853a574ad76f528cd1e7fe59d96a67458f5706d441435c7f1fdffb03129
5
+ SHA512:
6
+ metadata.gz: 503cf4e50f705609b9c4aaec1f71676c9ab1991778f05876b693836706abbb4f44c93f7a4cf2dff842ea8750417e54acb4b91ba4f82d2fcef2272d383ee045c4
7
+ data.tar.gz: c78ed3a31285dd7f0a35f4f10281fad6ef2345ae7d27afb4275fc85530e399cc434526e48dea30f44d83da056a6811a84bb80493922fc06c17cac46e93ddeb1b
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Francois Deschenes
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.
@@ -0,0 +1,34 @@
1
+ # OAuth2 Strategy for Facebook Long-Lived User Access Tokens
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/oauth2-fb-exchange-token-strategy.svg)](https://badge.fury.io/rb/oauth2-fb-exchange-token-strategy)
4
+ [![Coverage Status](https://coveralls.io/repos/github/fdeschenes/oauth2-fb-exchange-token-strategy/badge.svg?branch=master)](https://coveralls.io/github/fdeschenes/oauth2-fb-exchange-token-strategy?branch=master)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/34355bd39e55a168918a/maintainability)](https://codeclimate.com/github/fdeschenes/oauth2-fb-exchange-token-strategy/maintainability)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ As per Facebook, default User and Page access tokens are short-lived, expiring in hours, however, you can [exchange a short-lived token for a long-lived token](https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/).
9
+
10
+ This gem adds a new strategy to the excellent [oauth2](https://github.com/oauth-xx/oauth2) gem that can be used to do just that.
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ gem install oauth2_fb_exchange_token_strategy
16
+ ```
17
+
18
+ Or inside Gemfile
19
+
20
+ ```
21
+ gem 'oauth2_fb_exchange_token_strategy'
22
+ ```
23
+
24
+ ## Usage Examples
25
+
26
+ ```ruby
27
+ require 'oauth2'
28
+ require 'oauth2_fb_exchange_token_strategy'
29
+ client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://graph.facebook.com/v9.0', authorize_url: 'https://www.facebook.com/v8.0/dialog/oauth', token_url: 'oauth/access_token')
30
+
31
+ short_lived_token = client.auth_code.get_token('authorization_code_value', redirect_uri: 'http://example.org/oauth2/callback')
32
+ token = client.fb_exchange_token(short_lived_token.token)
33
+ # => OAuth2::AccessToken
34
+ ```
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth2
4
+ module Extension
5
+ module FbExchangeToken
6
+ def fb_exchange_token
7
+ @fb_exchange_token ||= OAuth2::Strategy::FbExchangeToken.new(self)
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ OAuth2::Client.include OAuth2::Extension::FbExchangeToken
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OAuth2
4
+ module Strategy
5
+ class FbExchangeToken < Base
6
+ def authorize_url
7
+ raise NotImplementedError, 'The authorization endpoint is not used in this strategy'
8
+ end
9
+
10
+ def get_token(access_token, params = {}, opts = {})
11
+ params = params.merge 'grant_type' => 'fb_exchange_token', 'fb_exchange_token' => access_token,
12
+ 'client_id' => @client.id, 'client_secret' => @client.secret
13
+ @client.get_token params, opts
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oauth2/extension/fb_exchange_token'
4
+ require 'oauth2/strategy/fb_exchange_token'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oauth2_fb_exchange_token_strategy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Francois Deschenes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: oauth2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1'
83
+ description:
84
+ email: fdeschenes@me.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - MIT-LICENSE
90
+ - README.md
91
+ - lib/oauth2/extension/fb_exchange_token.rb
92
+ - lib/oauth2/strategy/fb_exchange_token.rb
93
+ - lib/oauth2_fb_exchange_token_strategy.rb
94
+ homepage: https://github.com/fdeschenes/oauth2-fb-exchange-token-strategy
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 1.9.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: OAuth2 Strategy for Facebook Long-Lived User Access Tokens
117
+ test_files: []