devise-api 0.1.1 → 0.1.2
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +43 -1
- data/lib/devise/api/generators/install_generator.rb +0 -16
- data/lib/devise/api/generators/templates/migration.rb.erb +15 -2
- data/lib/devise/api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f6b2f86ff9cf332790f64f74212b25afff00bc6ff02ffe66389925db4b8fdc6
|
4
|
+
data.tar.gz: a7e8420897cf4e587a73a297d2121fcd0d20f4750deb01e9a7685bf4e635059b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5a5ec029117561416f93e6748f278f8489aeef2ec4ce832bce7136790a7587d93de2f5490bbbbfe4a202ccb4275c2f371012e435fdb7cb077999189372039f5
|
7
|
+
data.tar.gz: 43cad74cafb53ce017ebcf1e7ae41e250138eb9d8b0407ee89baf4ed8e2137394d4008f60c7c4f1f7116859aca43571361906a95ebbc1888348f71884f03a817
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -69,6 +69,8 @@ Your user model is now ready to use `devise-api` gem. It will draw routes for to
|
|
69
69
|
| sign_in_user_tokens | POST | /users/tokens/sign_in | devise/api/tokens#sign_in |
|
70
70
|
| info_user_tokens | GET | /users/tokens/info | devise/api/tokens#info |
|
71
71
|
|
72
|
+
### You can look up the [example requests](#example-api-requests).
|
73
|
+
|
72
74
|
## Configuration
|
73
75
|
|
74
76
|
`devise-api` is a full configurable gem. You can configure it to your needs. Here is a basic usage example:
|
@@ -226,9 +228,49 @@ class Api::V1::TokensController < YourBaseController
|
|
226
228
|
end
|
227
229
|
```
|
228
230
|
|
231
|
+
## Example API requests
|
232
|
+
|
233
|
+
### Sign in
|
234
|
+
```curl
|
235
|
+
curl --location --request POST 'http://127.0.0.1:3000/users/tokens/sign_in' \
|
236
|
+
--header 'Content-Type: application/json' \
|
237
|
+
--data-raw '{
|
238
|
+
"email": "test@development.com",
|
239
|
+
"password": "123456"
|
240
|
+
}'
|
241
|
+
```
|
242
|
+
|
243
|
+
### Sign up
|
244
|
+
```curl
|
245
|
+
curl --location --request POST 'http://127.0.0.1:3000/users/tokens/sign_up' \
|
246
|
+
--header 'Content-Type: application/json' \
|
247
|
+
--data-raw '{
|
248
|
+
"email": "test@development.com",
|
249
|
+
"password": "123456"
|
250
|
+
}'
|
251
|
+
```
|
252
|
+
|
253
|
+
### Refresh token
|
254
|
+
```curl
|
255
|
+
curl --location --request POST 'http://127.0.0.1:3000/users/tokens/refresh' \
|
256
|
+
--header 'Authorization: Bearer <refresh_token>'
|
257
|
+
```
|
258
|
+
|
259
|
+
### Revoke
|
260
|
+
```curl
|
261
|
+
curl --location --request POST 'http://127.0.0.1:3000/users/tokens/revoke' \
|
262
|
+
--header 'Authorization: Bearer <access_token>'
|
263
|
+
```
|
264
|
+
|
265
|
+
### Info
|
266
|
+
```curl
|
267
|
+
curl --location --request GET 'http://127.0.0.1:3000/users/tokens/info' \
|
268
|
+
--header 'Authorization: Bearer <access_token>'
|
269
|
+
```
|
270
|
+
|
229
271
|
## Development
|
230
272
|
|
231
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
273
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
232
274
|
|
233
275
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
234
276
|
|
@@ -40,22 +40,6 @@ module Devise
|
|
40
40
|
def migration_version
|
41
41
|
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
42
42
|
end
|
43
|
-
|
44
|
-
def primary_key_type
|
45
|
-
fallback = :integer
|
46
|
-
|
47
|
-
begin
|
48
|
-
ActiveRecord::Base.connection.supports_pgcrypto_uuid? ? :uuid : fallback
|
49
|
-
rescue StandardError
|
50
|
-
fallback
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def table_defaults_for_primary_key_type
|
55
|
-
return ', type: :uuid' if primary_key_type == :uuid
|
56
|
-
|
57
|
-
''
|
58
|
-
end
|
59
43
|
end
|
60
44
|
end
|
61
45
|
end
|
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
class CreateDeviseApiTables < ActiveRecord::Migration<%= migration_version %>
|
4
4
|
def change
|
5
|
-
|
6
|
-
|
5
|
+
# Use Active Record's configured type for primary and foreign keys
|
6
|
+
primary_key_type, foreign_key_type = primary_and_foreign_key_types
|
7
|
+
|
8
|
+
create_table :devise_api_tokens, id: primary_key_type do |t|
|
9
|
+
t.belongs_to :resource_owner, null: false, polymorphic: true, index: true, type: foreign_key_type
|
7
10
|
t.string :access_token, null: false, index: true
|
8
11
|
t.string :refresh_token, null: true, index: true
|
9
12
|
t.integer :expires_in, null: false
|
@@ -13,4 +16,14 @@ class CreateDeviseApiTables < ActiveRecord::Migration<%= migration_version %>
|
|
13
16
|
t.timestamps
|
14
17
|
end
|
15
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def primary_and_foreign_key_types
|
23
|
+
config = Rails.configuration.generators
|
24
|
+
setting = config.options[config.orm][:primary_key_type]
|
25
|
+
primary_key_type = setting || :primary_key
|
26
|
+
foreign_key_type = setting || :bigint
|
27
|
+
[primary_key_type, foreign_key_type]
|
28
|
+
end
|
16
29
|
end
|
data/lib/devise/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nejdetkadir
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
168
|
requirements: []
|
169
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.4.12
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: The devise-api gem is a convenient way to add authentication to your Ruby
|