fmrest 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +32 -1
- data/fmrest.gemspec +1 -0
- data/lib/fmrest/spyke/model.rb +2 -0
- data/lib/fmrest/spyke/model/auth.rb +35 -0
- data/lib/fmrest/v1/connection.rb +4 -2
- data/lib/fmrest/v1/token_session.rb +27 -0
- data/lib/fmrest/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 185e6173a3f500ea6fc8ad40df8f52ba538fdd8e3545537e947f19bfd79a3124
|
4
|
+
data.tar.gz: 89f5c6774366599e1baeef57662af77a3ceb5174abd58e6fd562c2aa29b85384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7aa56e455da60fe7b571e2ce4d70ae118ca7ade57356cbdade2b0679f66d10e9d689a4bc3af5ddfb06dfc6d7395af35b0518c23077dbfb28a9e395b845e0841
|
7
|
+
data.tar.gz: c764ee1dc1962b3f6264ed6a4f26f0b88dd5c69cb62bca93dd269398c3e0d350ced4177b2842ce24136d7d0b84cb9a4809ce23ca1965b923fb91fc7b37ae39e1
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -61,6 +61,28 @@ end
|
|
61
61
|
For each request fmrest-ruby will first request a session token (using the
|
62
62
|
provided username and password) if it doesn't yet have one in store.
|
63
63
|
|
64
|
+
### Logging out of the database session
|
65
|
+
|
66
|
+
The Data API requires sending a DELETE request to
|
67
|
+
`/fmi/data/:version/databases/:database_name/sessions/:session_token`
|
68
|
+
in order to log out from the session
|
69
|
+
([see docs](https://fmhelp.filemaker.com/docs/18/en/dataapi/#connect-database_log-out)).
|
70
|
+
|
71
|
+
Since fmrest-ruby handles the storage of session tokens internally, and the
|
72
|
+
token is required to build the logout URL, this becomes a non-trivial action.
|
73
|
+
|
74
|
+
To remedy this, fmrest-ruby connections recognize when you're trying to logout
|
75
|
+
and substitute whatever is in the `:session_token` section of the logout path
|
76
|
+
with the actual session token:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
# Logout from the database session
|
80
|
+
connection.delete "sessions/this-will-be-replaced-with-the-actual-token"
|
81
|
+
```
|
82
|
+
|
83
|
+
If you're using the ORM features this becomes much easier, see
|
84
|
+
[Model.logout](#modellogout) below.
|
85
|
+
|
64
86
|
## Connection settings
|
65
87
|
|
66
88
|
In addition to the required `:host`, `:database`, `:username` and `:password`
|
@@ -335,6 +357,15 @@ Data API models.
|
|
335
357
|
Note that you only need to set this if the name of the model and the name of
|
336
358
|
the layout differ, otherwise the default will just work.
|
337
359
|
|
360
|
+
### Model.logout
|
361
|
+
|
362
|
+
Use `logout` to log out from the database session (you may call it on any model
|
363
|
+
that uses the database session you want to log out from).
|
364
|
+
|
365
|
+
```ruby
|
366
|
+
Honeybee.logout
|
367
|
+
```
|
368
|
+
|
338
369
|
### Mapped Model.attributes
|
339
370
|
|
340
371
|
Spyke allows you to define your model's attributes using `attributes`, however
|
@@ -852,7 +883,7 @@ FM Data API reference: https://fmhelp.filemaker.com/docs/18/en/dataapi/
|
|
852
883
|
| Log in using OAuth | No | No |
|
853
884
|
| Log in to an external data source | No | No |
|
854
885
|
| Log in using a FileMaker ID account | No | No |
|
855
|
-
| Log out |
|
886
|
+
| Log out | Yes | Yes
|
856
887
|
| Get product information | Manual* | No |
|
857
888
|
| Get database names | Manual* | No |
|
858
889
|
| Get script names | Manual* | No |
|
data/fmrest.gemspec
CHANGED
data/lib/fmrest/spyke/model.rb
CHANGED
@@ -8,6 +8,7 @@ require "fmrest/spyke/model/associations"
|
|
8
8
|
require "fmrest/spyke/model/orm"
|
9
9
|
require "fmrest/spyke/model/container_fields"
|
10
10
|
require "fmrest/spyke/model/http"
|
11
|
+
require "fmrest/spyke/model/auth"
|
11
12
|
|
12
13
|
module FmRest
|
13
14
|
module Spyke
|
@@ -22,6 +23,7 @@ module FmRest
|
|
22
23
|
include Orm
|
23
24
|
include ContainerFields
|
24
25
|
include Http
|
26
|
+
include Auth
|
25
27
|
|
26
28
|
included do
|
27
29
|
# @return [Integer] the record's modId
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FmRest
|
4
|
+
module Spyke
|
5
|
+
module Model
|
6
|
+
module Auth
|
7
|
+
extend ::ActiveSupport::Concern
|
8
|
+
|
9
|
+
class_methods do
|
10
|
+
# Logs out the database session for this model (and other models
|
11
|
+
# using the same credentials).
|
12
|
+
#
|
13
|
+
# @raise [FmRest::V1::TokenSession::NoSessionTokenSet] if no session
|
14
|
+
# token was set (and no request is sent).
|
15
|
+
def logout!
|
16
|
+
connection.delete(FmRest::V1.session_path("dummy-token"))
|
17
|
+
end
|
18
|
+
|
19
|
+
# Logs out the database session for this model (and other models
|
20
|
+
# using the same credentials). Unlike `logout!`, no exception is
|
21
|
+
# raised in case of missing session token.
|
22
|
+
#
|
23
|
+
# @return [Boolean] Whether the logout request was sent (it's only
|
24
|
+
# sent if a session token was previously set)
|
25
|
+
def logout
|
26
|
+
logout!
|
27
|
+
true
|
28
|
+
rescue FmRest::V1::TokenSession::NoSessionTokenSet
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/fmrest/v1/connection.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "uri"
|
4
|
-
require "fmrest/v1/token_session"
|
5
|
-
require "fmrest/v1/raise_errors"
|
6
4
|
|
7
5
|
module FmRest
|
8
6
|
module V1
|
@@ -21,6 +19,7 @@ module FmRest
|
|
21
19
|
# @option (see #base_connection)
|
22
20
|
# @return (see #base_connection)
|
23
21
|
def build_connection(options = FmRest.default_connection_settings, &block)
|
22
|
+
|
24
23
|
base_connection(options) do |conn|
|
25
24
|
conn.use RaiseErrors
|
26
25
|
conn.use TokenSession, options
|
@@ -84,3 +83,6 @@ module FmRest
|
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
86
|
+
|
87
|
+
require "fmrest/v1/token_session"
|
88
|
+
require "fmrest/v1/raise_errors"
|
@@ -1,12 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "fmrest/v1/connection"
|
4
|
+
require "fmrest/errors"
|
5
|
+
|
3
6
|
module FmRest
|
4
7
|
module V1
|
5
8
|
# FM Data API authentication middleware using the credentials strategy
|
6
9
|
#
|
7
10
|
class TokenSession < Faraday::Middleware
|
11
|
+
class NoSessionTokenSet < FmRest::Error; end
|
12
|
+
|
8
13
|
HEADER_KEY = "Authorization".freeze
|
9
14
|
TOKEN_STORE_INTERFACE = [:load, :store, :delete].freeze
|
15
|
+
LOGOUT_PATH_MATCHER = %r{\A(#{FmRest::V1::Connection::BASE_PATH}/[^/]+/sessions/)[^/]+\Z}.freeze
|
10
16
|
|
11
17
|
def initialize(app, options = FmRest.default_connection_settings)
|
12
18
|
super(app)
|
@@ -16,6 +22,8 @@ module FmRest
|
|
16
22
|
# Entry point for the middleware when sending a request
|
17
23
|
#
|
18
24
|
def call(env)
|
25
|
+
return handle_logout(env) if is_logout_request?(env)
|
26
|
+
|
19
27
|
set_auth_header(env)
|
20
28
|
|
21
29
|
request_body = env[:body] # After failure env[:body] is set to the response body
|
@@ -32,6 +40,25 @@ module FmRest
|
|
32
40
|
|
33
41
|
private
|
34
42
|
|
43
|
+
def handle_logout(env)
|
44
|
+
token = token_store.load(token_store_key)
|
45
|
+
|
46
|
+
raise NoSessionTokenSet, "Couldn't send logout request because no session token was set" unless token
|
47
|
+
|
48
|
+
env.url.path = env.url.path.gsub(LOGOUT_PATH_MATCHER, "\\1#{token}")
|
49
|
+
|
50
|
+
@app.call(env).on_complete do |response_env|
|
51
|
+
if response_env[:status] == 200
|
52
|
+
token_store.delete(token_store_key)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def is_logout_request?(env)
|
58
|
+
return false unless env.method == :delete
|
59
|
+
return env.url.path.match?(LOGOUT_PATH_MATCHER)
|
60
|
+
end
|
61
|
+
|
35
62
|
def set_auth_header(env)
|
36
63
|
env.request_headers[HEADER_KEY] = "Bearer #{token}"
|
37
64
|
end
|
data/lib/fmrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fmrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Carbajal
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -204,6 +204,20 @@ dependencies:
|
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
name: yard-activesupport-concern
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
type: :development
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
207
221
|
description: FileMaker Data API client using Faraday, with optional ActiveRecord-like
|
208
222
|
ORM based on Spyke
|
209
223
|
email:
|
@@ -232,6 +246,7 @@ files:
|
|
232
246
|
- lib/fmrest/spyke/model.rb
|
233
247
|
- lib/fmrest/spyke/model/associations.rb
|
234
248
|
- lib/fmrest/spyke/model/attributes.rb
|
249
|
+
- lib/fmrest/spyke/model/auth.rb
|
235
250
|
- lib/fmrest/spyke/model/connection.rb
|
236
251
|
- lib/fmrest/spyke/model/container_fields.rb
|
237
252
|
- lib/fmrest/spyke/model/http.rb
|