Skip to content
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

async/await #94

Closed
wants to merge 1 commit into from
Closed

async/await #94

wants to merge 1 commit into from

Conversation

proggeramlug
Copy link

Not perfect but a starting point. Also definitely not tested for all providers.

I need this for Twitter/X and so I thought I'll bite the bullet and make it async/await.

@chibombo chibombo linked an issue Oct 25, 2023 that may be closed by this pull request

/// The route that the OAuth provider calls when the user has been authenticated.
///
/// - Parameter request: The request from the OAuth provider.
/// - Returns: A response that should redirect the user back to the app.
/// - Throws: An errors that occur in the implementation code.
func callback(_ request: Request) throws -> EventLoopFuture<Response>
func callback(_ request: Request) async throws -> Response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider the possible race conditions that this could cause. To mitigate the possibility of a race condition, we may add the @Sendable to the function definition.

Could you help us add that to the code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sendable should not be added to function declarations - it's a half broken implementation that currently just disables sendable checking inside that function. We should definitely enable Sendable checking on the library though

public var scope: [String] = []
public var callbackURL: String
public let accessTokenURL: String = "https://www.deviantart.com/oauth2/token"

public required init(callback: String, completion: @escaping (Request, String)throws -> (Future<ResponseEncodable>)) throws {
public required init(callback: String, completion: @escaping (Request, String)async throws -> Response) throws {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add the space between the async and the Request, String)?

router.get(callbackURL.pathComponents, use: callback)
router.get(authURL.pathComponents) { req -> EventLoopFuture<Response> in
public func configureRoutes(withAuthURL authURL: String, authenticateCallback: ((Request) async throws -> Void)?, on router: RoutesBuilder) async throws {
router.get(callbackURL.pathComponents, use: self.callback)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the self. if we are not in the init or closure?

@@ -16,7 +15,7 @@ public class GitHubRouter: FederatedServiceRouter {
return headers
}()

public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
public required init(callback: String, completion: @escaping (Vapor.Request, String) async throws -> Vapor.Response) async throws {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need to add the Vapor. declaration, Should we keep it?

@wibed
Copy link
Contributor

wibed commented Mar 11, 2024

any update?

@0xTim
Copy link
Member

0xTim commented Jul 31, 2024

Just an FYI I'm going to be doing an Imperial code sprint next week to go through all the issues and PRs

@bwdmr
Copy link

bwdmr commented Jul 31, 2024

i did a small rewrite, in which i applied the pattern of the jwt-kit and layered oauth on top of it.
if youd like to have a look:
https://github.com/bwdmr/oauth-kit

@0xTim
Copy link
Member

0xTim commented Dec 12, 2024

Closing in favour of #109

@0xTim 0xTim closed this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Maybe it is possible to update Imperial to async/await?
5 participants