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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7b573587b480d33fc2b6615142cdc7ca1c0215497fc3d3755d6a88b303a1788
4
- data.tar.gz: 4151e896ab7a40573a92bffa88383758dd96c4af22998ebc61a6167a82b9cfe1
3
+ metadata.gz: 4f6b2f86ff9cf332790f64f74212b25afff00bc6ff02ffe66389925db4b8fdc6
4
+ data.tar.gz: a7e8420897cf4e587a73a297d2121fcd0d20f4750deb01e9a7685bf4e635059b
5
5
  SHA512:
6
- metadata.gz: f5d4f26d865ea6d3341726017a82f66c911d088f518ca55fb4af10e4a01b5ed783cbee87aae6f5bca1e4fe6207d7db3404626ac6528fe1cf7b647d9e5b637bea
7
- data.tar.gz: 5789da3efd48c951b8199663f02a2bba978664b5a38a5c58c1fc752db5fb6eafdabb41af67d48241ff4bd7823a00b3b680a53e58f32ddb521164e05e858c5d83
6
+ metadata.gz: d5a5ec029117561416f93e6748f278f8489aeef2ec4ce832bce7136790a7587d93de2f5490bbbbfe4a202ccb4275c2f371012e435fdb7cb077999189372039f5
7
+ data.tar.gz: 43cad74cafb53ce017ebcf1e7ae41e250138eb9d8b0407ee89baf4ed8e2137394d4008f60c7c4f1f7116859aca43571361906a95ebbc1888348f71884f03a817
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devise-api (0.0.0)
4
+ devise-api (0.1.2)
5
5
  devise (>= 4.7.2)
6
6
  dry-configurable (~> 1.0, >= 1.0.1)
7
7
  dry-initializer (>= 3.1.1)
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 test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- create_table :devise_api_tokens<%= table_defaults_for_primary_key_type %> do |t|
6
- t.belongs_to :resource_owner, null: false<%= table_defaults_for_primary_key_type %>, polymorphic: true, index: true
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Devise
4
4
  module Api
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
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.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-01-14 00:00:00.000000000 Z
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.3.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