-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validations to exchange action in sessions controller
- Loading branch information
1 parent
8250acf
commit 08b2933
Showing
7 changed files
with
128 additions
and
5 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 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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Provides support for validating token claims | ||
module OAuthSessionExchangeable | ||
extend ActiveSupport::Concern | ||
|
||
VALID_URIS = ['/api/v1/users/current'].freeze | ||
VALID_TOKEN_TYPES = ['urn:ietf:params:oauth:token-type:access_token'].freeze | ||
|
||
def validate_params_for_exchange!(resource:, subject_token_type:) | ||
raise OAuth::InvalidResourceError unless valid_resource?(resource) | ||
|
||
return if valid_subject_token_type?(subject_token_type) | ||
|
||
raise OAuth::InvalidSubjectTokenTypeError | ||
end | ||
|
||
private | ||
|
||
def valid_resource?(resource) | ||
resource.present? && VALID_URIS.include?(resource) | ||
end | ||
|
||
def valid_subject_token_type?(subject_token_type) | ||
subject_token_type.present? && VALID_TOKEN_TYPES.include?(subject_token_type) | ||
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