-
Notifications
You must be signed in to change notification settings - Fork 62
Refactor device auth schema #1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a9e20c5
a195c9e
0af0e27
027d517
c4f4d01
77a0d8c
2b504ca
152fd2a
bf53d38
8ce7e42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4323,14 +4323,34 @@ impl DataStore { | |
| .values(access_token) | ||
| .returning(DeviceAccessToken::as_returning()); | ||
|
|
||
| #[derive(Debug)] | ||
| enum TokenGrantError { | ||
| ConcurrentRequests, | ||
| } | ||
| type TxnError = TransactionError<TokenGrantError>; | ||
|
|
||
| self.pool_authorized(opctx) | ||
| .await? | ||
| .transaction(move |conn| { | ||
| delete_request.execute(conn)?; | ||
| Ok(insert_token.get_result(conn)?) | ||
| if delete_request.execute(conn)? == 1 { | ||
| Ok(insert_token.get_result(conn)?) | ||
| } else { | ||
| Err(TxnError::CustomError( | ||
| TokenGrantError::ConcurrentRequests, | ||
|
||
| )) | ||
| } | ||
| }) | ||
| .await | ||
| .map_err(|e| public_error_from_diesel_pool(e, ErrorHandler::Server)) | ||
| .map_err(|e| match e { | ||
| TxnError::CustomError(TokenGrantError::ConcurrentRequests) => { | ||
| Error::invalid_request( | ||
| "token grant failed due to concurrent requests", | ||
| ) | ||
| } | ||
| TxnError::Pool(e) => { | ||
| public_error_from_diesel_pool(e, ErrorHandler::Server) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /// Look up a granted device access token. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.