vapor-community / Imperial

Federated Authentication with OAuth providers
MIT License
153 stars 48 forks source link

id like to rename callback to redirectURL #97

Open wibed opened 5 months ago

wibed commented 5 months ago

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

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 commented 1 month ago

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