-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Little refactor to separate app_registry from auth
- Loading branch information
Showing
4 changed files
with
44 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Services | ||
class AppRegistryService | ||
def authenticate!(token) | ||
identity = decode(token) | ||
raise AuthError unless identity | ||
# TODO verify identity with authority? | ||
identity | ||
end | ||
|
||
def authorize!(identity, cert_req) | ||
cert_req.fqdns.each do |fqdn| | ||
domain = get_domain_name(fqdn) | ||
raise AuthError unless (domain[:auto_approved_groups] & identity[:groups]).any? | ||
end | ||
end | ||
|
||
private | ||
|
||
def decode(token) | ||
# Decode a JWT access token using the configured base. | ||
body = JWT.decode(token, Rails.application.config.astral[:jwt_signing_key])[0] | ||
HashWithIndifferentAccess.new body | ||
rescue => e | ||
Rails.logger.warn "Unable to decode token: #{e}" | ||
nil | ||
end | ||
|
||
def get_domain_name(fqdn) | ||
# TODO implement | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
module Services | ||
class AuthService | ||
def decode(token) | ||
# Decode a JWT access token using the configured base. | ||
body = JWT.decode(token, Rails.application.config.astral[:jwt_signing_key])[0] | ||
HashWithIndifferentAccess.new body | ||
rescue => e | ||
Rails.logger.warn "Unable to decode token: #{e}" | ||
nil | ||
end | ||
def initialize | ||
# TODO make this selectable | ||
@impl = AppRegistryService.new | ||
end | ||
|
||
def authenticate!(token) | ||
identity = decode(token) | ||
raise AuthError unless identity | ||
# TODO verify identity with authority? | ||
identity | ||
end | ||
def authenticate!(token) | ||
@impl.authenticate!(token) | ||
end | ||
|
||
def authorize!(identity, cert_req) | ||
cert_req.fqdns.each do |fqdn| | ||
domain = AppRegistryService.get_domain_name(fqdn) | ||
raise AuthError unless (domain[:auto_approved_groups] & identity[:groups]).any? | ||
end | ||
end | ||
def authorize!(token, cert_issue_req) | ||
@impl.authorize!(token, cert_issue_req) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters