forked from postalserver/postal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticator.rb
More file actions
29 lines (28 loc) · 1020 Bytes
/
authenticator.rb
File metadata and controls
29 lines (28 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
authenticator :server do
friendly_name "Server Authenticator"
header "X-Server-API-Key", "The API token for a server that you wish to authenticate with.", :example => 'f29a45f0d4e1744ebaee'
error 'InvalidServerAPIKey', "The API token provided in X-Server-API-Key was not valid.", :attributes => {:token => "The token that was looked up"}
error 'ServerSuspended', "The mail server has been suspended"
lookup do
if key = request.headers['X-Server-API-Key']
if credential = Credential.where(:type => 'API', :key => key).first
if credential.server.suspended?
error 'ServerSuspended'
else
credential.use
credential
end
else
error 'InvalidServerAPIKey', :token => key
end
end
end
rule :default, "AccessDenied", "Must be authenticated as a server." do
identity.is_a?(Credential)
end
end
authenticator :anonymous do
rule :default, "MustNotBeAuthenticated", "Must not be authenticated." do
identity.nil?
end
end