This repository has been archived by the owner on Jan 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Update FK api #85
Merged
Merged
Update FK api #85
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -40,21 +40,29 @@ def request_clubnames | |
return Club.pluck(:internal_name) if Rails.env.development? | ||
|
||
ugent_login = session[:cas]['user'] | ||
|
||
def digest(*args) | ||
Digest::SHA256.hexdigest args.join('-') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 256 is a magic number, please abstract! Also digest function should be set in config, because it can change |
||
end | ||
|
||
# using httparty because it is much easier to read than net/http code | ||
resp = HTTParty.get(Rails.application.secrets.fk_auth_url, :query => { | ||
:k => digest(ugent_login, Rails.application.secrets.fk_auth_key), | ||
:u => ugent_login | ||
}) | ||
resp = HTTParty.get("#{ Rails.application.secrets.fk_auth_url }/#{ ugent_login }/FKEnrolment", | ||
headers: { | ||
'X-Authorization': Rails.application.secrets.fk_auth_key, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Accept: 'application/json' | ||
}) | ||
|
||
# this will only return the club names if control-hash matches | ||
if resp.body != 'FAIL' | ||
if resp.success? | ||
hash = JSON[resp.body] | ||
dig = digest(Rails.application.secrets.fk_auth_salt, ugent_login, hash['clubnames']) | ||
return hash['clubnames'] if hash['control'] == dig | ||
clubs = hash['clubs'].map do |club| club['internal_name'] end | ||
timestamp = hash['timestamp'] | ||
|
||
max_time_difference = 5*60 # Timestamp can't differ by more than 5 minutes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 magic numbers for the price of one |
||
return [] unless (Time.now - DateTime.parse(timestamp)).abs < max_time_difference | ||
dig = digest(Rails.application.secrets.fk_auth_salt, ugent_login, timestamp, clubs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where you gonna start digging? |
||
|
||
return clubs if hash['sign'] == dig | ||
end | ||
[] | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random line