omniauth-gitbook 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03ec192ce62502ee32acf3208e75967a4c12551c
4
- data.tar.gz: 743591d69227924f045040262cddbb8fa2f80a94
3
+ metadata.gz: ee583cbf4ff6b57a2097f9c9de4699c600a3350d
4
+ data.tar.gz: 062f4ee514935ee18bf0709a15107bc10020f7bf
5
5
  SHA512:
6
- metadata.gz: 9700390f8f898435748e048c94cb3f3c1a58f0ee389b1064cc8afc85ec8ee976d9bd07959d7a4a4b95e9a554a1188eb4e78dd3d58d16cc5fd3465e7c1671c59b
7
- data.tar.gz: 49d2099169d38938b1ff9cebb534d82ed7efc4f4ea970e8047ad7e9db2a20ef5ce558691df97ec3bb7d81efb327fdf85ef1e3785a06bfe1e34a9b6d6bf531644
6
+ metadata.gz: b2a0cadc2b47c8e8de432ee9985c9b39124ff8a3905e82f962203e17e7f13af6f43546c68bba563157c4daaa481a8fc5a341a2ce3a6f65291c266dabfd5cfa06
7
+ data.tar.gz: 52d58116143cd438a18873078cb65dbbc704a9e8622d32453268620a319264b36475450a134a820fe36593bddc4f7dbcd4948ba68100a75981d9087aa694bce0
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm: 2.3.1
3
+
4
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,2 +1,239 @@
1
- # omniauth-gitbook
1
+ # omniauth-gitbook ![](https://travis-ci.org/Calvin-Huang/omniauth-gitbook.svg?branch=master) ![gem](https://img.shields.io/badge/gem-1.0.0-red.svg)
2
2
  Gitbook Oauth2 strategy for Omniauth.
3
+
4
+ ## Usage - OmniAuth
5
+ If you only integrate OmniAuth to your project, follows to [OmniAuth offical document](https://github.com/omniauth/omniauth), you have to add callback route and have a controller to handle data from oauth exchange.
6
+
7
+ Before all, add configuration for omniauth-gotbook at `config/initializers/omniauth.rb`.
8
+ ```ruby
9
+ Rails.application.config.middleware.use OmniAuth::Builder do
10
+ provider :developer unless Rails.env.production?
11
+ provider :gitbook, ENV['CLIENT_ID'], ENV['CLIENT_SECRET']
12
+ end
13
+ ```
14
+
15
+ Add callback route to `route.rb`.
16
+ ```ruby
17
+ get '/auth/:provider/callback', to: 'sessions#create'
18
+ ```
19
+
20
+ Handle json data in controller.
21
+ ```ruby
22
+ class SessionsController < ApplicationController
23
+ def create
24
+ @user = User.find_or_create_from_auth_hash(auth_hash)
25
+ self.current_user = @user
26
+ redirect_to '/'
27
+ end
28
+
29
+ protected
30
+
31
+ def auth_hash
32
+ request.env['omniauth.auth']
33
+ end
34
+ end
35
+ ```
36
+
37
+ ## Usage - Devise
38
+ If you integrate Devise to your rails project, follows to [Devise - OmniAuth: Overview](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview), here are some steps.
39
+
40
+ If you have no `config/initializers/devise.rb`, run the generator.
41
+ ```
42
+ rails g devise:install
43
+ ```
44
+
45
+ Add configuration to `config/initializers/devise.rb` for omniauth-gitbook.
46
+ ```ruby
47
+ Devise.setup do |config|
48
+ config.omniauth :gitbook, [CLIENT_ID], [CLIENT_SECRET]
49
+ end
50
+ ```
51
+
52
+ And if your devise model named `User`, add callback route to `route.rb`.
53
+ ```ruby
54
+ devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
55
+ ```
56
+
57
+ Then you can get user's data in controller.
58
+ ```ruby
59
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
60
+ def gitbook
61
+ @user = User.find_or_create_by_oauth2(request.env[omniauth.auth])
62
+
63
+ if @user.persisted?
64
+ sign_in_and_redirect_to root_path, event: :authentication
65
+ end
66
+ end
67
+ end
68
+ ```
69
+
70
+ ## What data exactly you retrieved from `omniauth-gitbook`
71
+ Here is the json structure.
72
+ ```json
73
+ {
74
+ "provider":"gitbook",
75
+ "uid":"[UID]",
76
+ "info":{
77
+ "username":"calvinhuang",
78
+ "name":"Calvin-Huang",
79
+ "website":"https://github.com/Calvin-Huang",
80
+ "urls":{
81
+ "profile":"https://www.gitbook.com/@calvin-huang",
82
+ "stars":"https://www.gitbook.com/@calvin-huang/starred",
83
+ "avatar":"https://avatars0.githubusercontent.com/Calvin-Huang"
84
+ },
85
+ "auth":{
86
+ "token":"[TOKEN]",
87
+ "password":false,
88
+ "verified":false
89
+ },
90
+ "token":"[TOKEN]"
91
+ },
92
+ "credentials":{
93
+ "token":"[TOKEN]",
94
+ "expires":false
95
+ },
96
+ "extra":{
97
+ "raw_info":{
98
+ "id":"[UID]",
99
+ "type":"User",
100
+ "username":"calvinhuang",
101
+ "name":"Calvin-Huang",
102
+ "location":"",
103
+ "website":"https://github.com/Calvin-Huang",
104
+ "verified":false,
105
+ "locked":false,
106
+ "site_admin":false,
107
+ "urls":{
108
+ "profile":"https://www.gitbook.com/@calvin-huang",
109
+ "stars":"https://www.gitbook.com/@calvin-huang/starred",
110
+ "avatar":"https://avatars0.githubusercontent.com/calvin-huang"
111
+ },
112
+ "permissions":{
113
+ "edit":true,
114
+ "admin":true
115
+ },
116
+ "dates":{
117
+ "created":"2016-10-01T08:51:37.391Z"
118
+ },
119
+ "counts":{
120
+
121
+ },
122
+ "github":{
123
+ "username":"Calvin-Huang",
124
+ "scopes":[
125
+ ""
126
+ ],
127
+ "required":true
128
+ },
129
+ "plan":{
130
+ "id":"free"
131
+ },
132
+ "auth":{
133
+ "token":"[TOKEN]",
134
+ "password":false,
135
+ "verified":false
136
+ },
137
+ "token":"[TOKEN]"
138
+ }
139
+ },
140
+ "books":{
141
+ "list":[
142
+ {
143
+ "id":"calvinhuang/test",
144
+ "status":"published",
145
+ "name":"test",
146
+ "title":"test",
147
+ "description":"",
148
+ "public":true,
149
+ "topics":[
150
+
151
+ ],
152
+ "license":"nolicense",
153
+ "language":"en",
154
+ "locked":false,
155
+ "cover":{
156
+ "large":"[URL]",
157
+ "small":"[URL]"
158
+ },
159
+ "urls":{
160
+ "git":"https://git.gitbook.com/calvinhuang/test.git",
161
+ "access":"https://www.gitbook.com/book/calvinhuang/test",
162
+ "homepage":"https://calvinhuang.gitbooks.io/test/",
163
+ "read":"https://www.gitbook.com/read/book/calvinhuang/test",
164
+ "edit":"https://www.gitbook.com/book/calvinhuang/test/edit",
165
+ "content":"https://fennyliang.gitbooks.io/test/content/",
166
+ "download":{
167
+ "epub":"https://www.gitbook.com/download/epub/book/calvinhuang/test",
168
+ "mobi":"https://www.gitbook.com/download/mobi/book/calvinhuang/test",
169
+ "pdf":"https://www.gitbook.com/download/pdf/book/calvinhuang/test"
170
+ }
171
+ },
172
+ "counts":{
173
+ "stars":0,
174
+ "subscriptions":1,
175
+ "updates":1,
176
+ "discussions":0,
177
+ "collaborators":0
178
+ },
179
+ "dates":{
180
+ "build":"2016-10-03T05:29:17.696Z",
181
+ "created":"2016-10-03T05:28:37.865Z"
182
+ },
183
+ "permissions":{
184
+ "edit":true,
185
+ "admin":true,
186
+ "important":true
187
+ },
188
+ "publish":{
189
+ "defaultBranch":"master",
190
+ "builder":"default"
191
+ },
192
+ "author":{
193
+ "id":"[UID]",
194
+ "type":"User",
195
+ "username":"calvinhuang",
196
+ "name":"Calvin-Huang",
197
+ "location":"",
198
+ "website":"https://github.com/Calvin-Huang",
199
+ "verified":false,
200
+ "locked":false,
201
+ "site_admin":false,
202
+ "urls":{
203
+ "profile":"https://www.gitbook.com/@calvinhuang",
204
+ "stars":"https://www.gitbook.com/@calvinhuang/starred",
205
+ "avatar":"https://avatars0.githubusercontent.com/Calvin-Huang"
206
+ },
207
+ "permissions":{
208
+ "edit":null,
209
+ "admin":null
210
+ },
211
+ "dates":{
212
+ "created":"2016-10-01T08:51:37.391Z"
213
+ },
214
+ "counts":{
215
+
216
+ },
217
+ "github":{
218
+ "username":"Calvin-Huang"
219
+ }
220
+ }
221
+ }
222
+ ],
223
+ "total":1,
224
+ "limit":50,
225
+ "page":0,
226
+ "pages":1
227
+ }
228
+ }
229
+ ```
230
+
231
+ ## TO-DO
232
+ - [ ] Paginate books.
233
+ - [ ] Provide Gem to interact with GitBook API.
234
+
235
+ ## Contribution
236
+ I'm appreciate at any improvement, please feel free to open PR / Issue to this repo or you can contact [me](https://github.com/Calvin-Huang).
237
+
238
+ ## License
239
+ Copyright (c) [Calvin Huang](https://github.com/Calvin-Huang). This software is licensed under the [MIT License](https://github.com/Calvin-Huang/CHRealHideUIView/blob/master/LICENSE).
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GitBook
3
- VERSION = '0.0.4'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -11,10 +11,6 @@ module OmniAuth
11
11
  token_url: "#{base_url}/oauth/access_token",
12
12
  }
13
13
 
14
- option :token_params, {
15
- grant_type: 'authorization_code'
16
- }
17
-
18
14
  uid { raw_info['id'].to_s }
19
15
 
20
16
  info do
@@ -29,14 +25,17 @@ module OmniAuth
29
25
  end
30
26
 
31
27
  extra do
32
- { raw_info: raw_info }
28
+ { raw_info: raw_info, books: books }
33
29
  end
34
30
 
35
31
  def raw_info
36
- access_token.options[:mode] = :query
37
32
  @raw_info ||= access_token.get('account').parsed
38
33
  end
39
34
 
35
+ def books
36
+ @books ||= access_token.get('books').parsed
37
+ end
38
+
40
39
  def authorize_params
41
40
  super.tap do |params|
42
41
  %w[response_type].each do |v|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-gitbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Huang
@@ -109,6 +109,7 @@ extra_rdoc_files: []
109
109
  files:
110
110
  - ".gitignore"
111
111
  - ".rspec"
112
+ - ".travis.yml"
112
113
  - Gemfile
113
114
  - Guardfile
114
115
  - LICENSE