zas-service 0.0.7 → 0.1.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.
- data/README.md +22 -0
- data/lib/zas/service.rb +9 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -32,6 +32,28 @@ Running from irb:
|
|
32
32
|
bundle exec irb -Ilib -rzas
|
33
33
|
=> # as above
|
34
34
|
|
35
|
+
## Adding Support for Other Authenticators
|
36
|
+
|
37
|
+
To create a custom authenticator, your class must respond to the `#authenticate` method. Currently the signature for the `#authenticate` method is dependent on your authenticator's needs. By default the value associated with the credentials key from the request will be passed straight through to your `#authenticate` implementation.
|
38
|
+
|
39
|
+
For example, if the request is:
|
40
|
+
|
41
|
+
{
|
42
|
+
"strategy": "my_auth",
|
43
|
+
"credentials": "foo!"
|
44
|
+
}
|
45
|
+
|
46
|
+
And your authenticator is:
|
47
|
+
|
48
|
+
class MyAuthenticator
|
49
|
+
attr_accessor :logger
|
50
|
+
def authenticate(credentials)
|
51
|
+
credentials == 'foo!'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Note that the attr_accessor :logger is not required, however if you provide it then your authenticator will have access to the syslog logger.
|
56
|
+
|
35
57
|
## Configuration
|
36
58
|
|
37
59
|
You may provide a service configuration to the service initializer:
|
data/lib/zas/service.rb
CHANGED
@@ -71,7 +71,7 @@ module Zas
|
|
71
71
|
req = Hashie::Mash.new(Yajl::Parser.parse(req_string))
|
72
72
|
authenticator = authenticators[req.strategy]
|
73
73
|
raise "No authenticator found for #{req.strategy}" unless authenticator
|
74
|
-
authenticator
|
74
|
+
assign_logger_to_authenticator(authenticator)
|
75
75
|
{:authenticated? => (authenticator.authenticate(req.credentials) || false)}
|
76
76
|
rescue => e
|
77
77
|
logger.info "Error authenticating: #{e.message}"
|
@@ -86,5 +86,13 @@ module Zas
|
|
86
86
|
def encode(data)
|
87
87
|
Yajl::Encoder.encode(data)
|
88
88
|
end
|
89
|
+
|
90
|
+
def assign_logger_to_authenticator(authenticator)
|
91
|
+
begin
|
92
|
+
authenticator.logger ||= logger
|
93
|
+
rescue NoMethodError => e
|
94
|
+
logger.warn "The #{authenticator.class.name} does not provide a means to set the logger"
|
95
|
+
end
|
96
|
+
end
|
89
97
|
end
|
90
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zas-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zmq
|