This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Save OAuth tokens #2810
Merged
Merged
Save OAuth tokens #2810
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a60148
save elsewhere auth tokens in the DB
Changaco fac7bea
add a simplate that uses the elsewhere tokens to refresh the user's data
Changaco 6ef236b
Update Venmo testing app
chadwhitacre 73cd70c
Fix bug with 403 code path
chadwhitacre 6baaeba
Fix Venmo callback to match the one in the app
chadwhitacre 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
BEGIN; | ||
ALTER TABLE elsewhere DROP COLUMN access_token, | ||
DROP COLUMN refresh_token, | ||
DROP COLUMN expires; | ||
ALTER TABLE elsewhere ADD COLUMN token json; | ||
|
||
DROP TYPE elsewhere_with_participant CASCADE; | ||
CREATE TYPE elsewhere_with_participant AS | ||
( id integer | ||
, platform text | ||
, user_id text | ||
, user_name text | ||
, display_name text | ||
, email text | ||
, avatar_url text | ||
, extra_info json | ||
, is_locked boolean | ||
, is_team boolean | ||
, token json | ||
, participant participants | ||
); -- If Postgres had type inheritance this would be even awesomer. | ||
|
||
CREATE OR REPLACE FUNCTION load_participant_for_elsewhere (elsewhere) | ||
RETURNS elsewhere_with_participant | ||
AS $$ | ||
SELECT $1.id | ||
, $1.platform | ||
, $1.user_id | ||
, $1.user_name | ||
, $1.display_name | ||
, $1.email | ||
, $1.avatar_url | ||
, $1.extra_info | ||
, $1.is_locked | ||
, $1.is_team | ||
, $1.token | ||
, participants.*::participants | ||
FROM participants | ||
WHERE participants.username = $1.participant | ||
; | ||
$$ LANGUAGE SQL; | ||
|
||
CREATE CAST (elsewhere AS elsewhere_with_participant) | ||
WITH FUNCTION load_participant_for_elsewhere(elsewhere); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from aspen import Response | ||
from gratipay.models.account_elsewhere import AccountElsewhere | ||
from gratipay.utils import get_participant | ||
|
||
[---] | ||
|
||
if not user.ADMIN: | ||
raise Response(403) | ||
|
||
participant = get_participant(request, restrict=True) | ||
accounts = participant.get_accounts_elsewhere() | ||
i = 0 | ||
for account in accounts.values(): | ||
sess = account.get_auth_session() | ||
if not sess: | ||
continue | ||
AccountElsewhere.upsert(account.platform_data.get_user_self_info(sess)) | ||
i += 1 | ||
|
||
[---] text/html | ||
Updated {{i}} accounts. |
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.
What about the data that's already in these columns? It looks like we're throwing it away, yes? Why?
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.
Because keeping it is not worth the effort, it only exists in 59 rows (Venmo accounts), and I think it might be obsolete anyway.
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.
Okay. We've been using an OAuth app for Venmo that is attached to my personal account. Due to bugs on their end we were unable to set up an app under our Gratipay account, but I believe that's resolved now. What are the implications of throwing away these access/refresh tokens? Does it make sense to also switch to a different Venmo OAuth app along with this PR?
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.
Yes, if we want to change some OAuth keys now is the time.
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.
Okay, I'll look into it.