-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #238 from cbdr/oauth-scopes-fix-and-refactor"
- Loading branch information
1 parent
d692b87
commit e1c5a7c
Showing
17 changed files
with
176 additions
and
162 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
This file was deleted.
Oops, something went wrong.
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
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,70 @@ | ||
module V1 | ||
module Helpers | ||
module APIHelper | ||
def logger | ||
::API.logger | ||
end | ||
|
||
# Authentication and Authorization | ||
def authenticate! | ||
unauthorized! unless current_user | ||
end | ||
|
||
def authorize!(action, subject) | ||
unless abilities.allowed?(current_user, action, subject) | ||
forbidden! | ||
end | ||
end | ||
|
||
def require_scope!(scopes) | ||
return unless find_access_token | ||
scopes = [scopes] unless scopes.kind_of? Array | ||
|
||
unless (find_access_token.scopes.to_a & scopes) == scopes | ||
# TODO: Scopes are historically completely broken in Cortex. This is quite the security issue: fix! | ||
puts 'SCOPES are currently being IGNORED' | ||
# forbidden! | ||
end | ||
end | ||
|
||
def current_tenant | ||
current_user.tenant | ||
end | ||
|
||
def can?(object, action, subject) | ||
abilities.allowed?(object, action, subject) | ||
end | ||
|
||
# API Errors | ||
def bad_request! | ||
render_api_error!('(400) Bad Request', 400) | ||
end | ||
|
||
def forbidden! | ||
render_api_error!('(403) Forbidden', 403) | ||
end | ||
|
||
def not_found! | ||
render_api_error!('(404) Not found', 404) | ||
end | ||
|
||
def unauthorized! | ||
render_api_error!('(401) Unauthorized', 401) | ||
end | ||
|
||
def render_api_error!(message, status) | ||
error!({message: message}, status) | ||
end | ||
|
||
private | ||
|
||
def abilities | ||
@abilities ||= begin | ||
abilities = Six.new | ||
abilities << Abilities::Ability | ||
abilities | ||
end | ||
end | ||
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
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
Oops, something went wrong.