rack-alice_in_external 0.1.0 → 0.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85deba78ea3b2ea75aa8ee4d681e1d63a020fe3
|
4
|
+
data.tar.gz: e2a9548a15588915f1d9a90ef1c73449d9b2dab7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 846a991636c47a3c2cd5917d75c6e8395b14ae393f10d7c979a3c4b26cd39e550ae05dd5690258816432434d2d25019f1bc03e7dcc2789d8404605ebe5ed323b
|
7
|
+
data.tar.gz: 47ff5b201bd6c2b8fa8dcc2f9f40b59a8f72699b2c734b8daf1f1e477a9e77900bcec4678db5f1adb370925a6c42d0168a6188a1a50572327b76f453e1b01101
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ gem 'rack-alice_in_external'
|
|
48
48
|
|
49
49
|
## Usage
|
50
50
|
|
51
|
-
Rack::AliceInExternal
|
51
|
+
Rack::AliceInExternal stubs the external requests and returns the user information as a response which includes `uid: 42`. So if the user with an association to the `uid: 42` record in `authentications` table exists, Sorcery makes that user login, otherwise a new user is created (and you cannot change `uid` other than `42`).
|
52
52
|
|
53
53
|
Fixture examples:
|
54
54
|
|
@@ -2,9 +2,6 @@
|
|
2
2
|
#
|
3
3
|
# Assume you have built the controller following to the below post:
|
4
4
|
# https://github.com/NoamB/sorcery/wiki/External
|
5
|
-
#
|
6
|
-
# Requires a user has an associtation with authentications(uid: 42)
|
7
5
|
|
8
6
|
require 'rack/alice_in_external/version'
|
9
|
-
require 'rack/alice_in_external/webmock_stubs'
|
10
7
|
require 'rack/alice_in_external/github_mock'
|
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'webmock'
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
module AliceInExternal
|
3
5
|
class GithubMock
|
6
|
+
include WebMock::API
|
7
|
+
|
4
8
|
def initialize(app)
|
9
|
+
stub_external_requests!
|
5
10
|
@app = app
|
6
11
|
end
|
7
12
|
|
@@ -11,6 +16,60 @@ module Rack
|
|
11
16
|
end
|
12
17
|
@app.call(env)
|
13
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def stub_external_requests!
|
23
|
+
# Stubbing external request for GitHub OAuth via WebMock
|
24
|
+
stub_request(:post, 'https://github.com/login/oauth/access_token')
|
25
|
+
.to_return(body: 'access_token=charleslutwidgedodgson&scope=user%2Cgist&token_type=bearer',
|
26
|
+
headers: { 'content-type' => 'application/x-www-form-urlencoded' })
|
27
|
+
|
28
|
+
stub_request(:get, 'https://api.github.com/user')
|
29
|
+
.to_return(body: user_info,
|
30
|
+
headers: { 'content-type' => 'application/json' })
|
31
|
+
|
32
|
+
WebMock.enable!
|
33
|
+
WebMock.allow_net_connect!
|
34
|
+
end
|
35
|
+
|
36
|
+
def user_info
|
37
|
+
<<-JSON
|
38
|
+
{
|
39
|
+
"login": "alice",
|
40
|
+
"id": 42,
|
41
|
+
"avatar_url": "https://avatars.githubusercontent.com/u/42?v=3",
|
42
|
+
"gravatar_id": "",
|
43
|
+
"url": "https://api.github.com/users/alice",
|
44
|
+
"html_url": "https://github.com/alice",
|
45
|
+
"followers_url": "https://api.github.com/users/alice/followers",
|
46
|
+
"following_url": "https://api.github.com/users/alice/following{/other_user}",
|
47
|
+
"gists_url": "https://api.github.com/users/alice/gists{/gist_id}",
|
48
|
+
"starred_url": "https://api.github.com/users/alice/starred{/owner}{/repo}",
|
49
|
+
"subscriptions_url": "https://api.github.com/users/alice/subscriptions",
|
50
|
+
"organizations_url": "https://api.github.com/users/alice/orgs",
|
51
|
+
"repos_url": "https://api.github.com/users/alice/repos",
|
52
|
+
"events_url": "https://api.github.com/users/alice/events{/privacy}",
|
53
|
+
"received_events_url": "https://api.github.com/users/alice/received_events",
|
54
|
+
"type": "User",
|
55
|
+
"site_admin": false,
|
56
|
+
"name": "Alice Liddell",
|
57
|
+
"company": null,
|
58
|
+
"blog": "http://alice-in-wonderland.example.com",
|
59
|
+
"location": "Wonderland",
|
60
|
+
"email": "alice@example.com",
|
61
|
+
"hireable": null,
|
62
|
+
"bio": null,
|
63
|
+
"public_repos": 10,
|
64
|
+
"public_gists": 20,
|
65
|
+
"followers": 30,
|
66
|
+
"following": 40,
|
67
|
+
"created_at": "2010-07-15T16:14:02Z",
|
68
|
+
"updated_at": "2016-05-12T10:08:11Z"
|
69
|
+
}
|
70
|
+
JSON
|
71
|
+
end
|
14
72
|
end
|
15
73
|
end
|
16
74
|
end
|
75
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-alice_in_external
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirofumi Wakasugi
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- lib/rack/alice_in_external.rb
|
86
86
|
- lib/rack/alice_in_external/github_mock.rb
|
87
87
|
- lib/rack/alice_in_external/version.rb
|
88
|
-
- lib/rack/alice_in_external/webmock_stubs.rb
|
89
88
|
- rack-alice_in_external.gemspec
|
90
89
|
homepage: https://github.com/5t111111/rack-alice_in_external
|
91
90
|
licenses: []
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'webmock'
|
2
|
-
|
3
|
-
include WebMock::API
|
4
|
-
|
5
|
-
# Stubbing external request for GitHub OAuth via WebMock
|
6
|
-
stub_request(:post, 'https://github.com/login/oauth/access_token')
|
7
|
-
.to_return(body: 'access_token=charleslutwidgedodgson&scope=user%2Cgist&token_type=bearer',
|
8
|
-
headers: { 'content-type' => 'application/x-www-form-urlencoded' })
|
9
|
-
|
10
|
-
stub_request(:get, 'https://api.github.com/user')
|
11
|
-
.to_return(body:'{"id":42,"email":"alice@example.com"}',
|
12
|
-
headers: { 'content-type' => 'application/json' })
|
13
|
-
|
14
|
-
WebMock.enable!
|
15
|
-
WebMock.allow_net_connect!
|