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

id like to rename callback to redirectURL #97

Open
wibed opened this issue Mar 12, 2024 · 1 comment
Open

id like to rename callback to redirectURL #97

wibed opened this issue Mar 12, 2024 · 1 comment

Comments

@wibed
Copy link
Contributor

wibed commented Mar 12, 2024

variable representing the redirectURL, which is dictated by the oauth2 provider.
is named callback.

example:

public class GitlabRouter: FederatedServiceRouter {
...
    public required init(callback: String, completion: @escaping (Request, String) throws ->
...

a few router have a callbackURL, representing the same thing this hardcoded. example:

    public static var baseURL: String = "https://gitlab.com/"
    public static var callbackURL: String = "callback"

on top a function which handles the "callback" made on the "callback" sometimes referred to as "callbackURL" is named... you guessed it. "callback"

    public func callback(_ request: Request) throws -> EventLoopFuture<Response> {
        return try self.fetchToken(from: request).flatMap { accessToken in
            let session = request.session
            do {
                try session.setAccessToken(accessToken)
                try session.set("access_token_service", to: self.service)
                return try self.callbackCompletion(request, accessToken).flatMap { response in
                    return response.encodeResponse(for: request)
                }
            } catch {
                return request.eventLoop.makeFailedFuture(error)
            }
        }
    }

additionally callback is a reserved word, in a sense it is a descriptive term well known in IT.

for all these reasons, id like to rename it. following changes would apply

  • callback passed to FederatedServiceRouter should be named redirectURL/redirectURI, because it is the copied value from the oauth provider named redirect_uri .
  • callback function which handles the route for the redirect_uri, would be named handleoauthRedirect
  • files representing related content, GoogleCallbackBody.swift´, would be renamed to GoogleOauthRedirectBody.swift`

furthermore what is the background behind those static references?

// ImperialDiscord/DiscordRouter.swift
...
public class DiscordRouter: FederatedServiceRouter {
    public static var baseURL: String = "https://discord.com/"
    public static var callbackURL: String = "callback"
...
        var components = URLComponents()
        components.scheme = "https"
        components.host = "discord.com"
        components.path = "/api/oauth2/authorize"
        components.queryItems = [
            clientIDItem,
            .init(name: "redirect_uri", value: DiscordRouter.callbackURL),
            .init(name: "response_type", value: "code"),
            scopeItem
        ]

the auth url could only be wrong for it would not be dictated by the provider.
this ill let be, for the moment...

all is open for discussion! please let me know what you thing, your input and thoughts.

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants