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

🚀 Feature: OAuth2 allow for additional query parameters #3552

Open
2 tasks done
codercatdev opened this issue Jul 17, 2022 · 1 comment
Open
2 tasks done

🚀 Feature: OAuth2 allow for additional query parameters #3552

codercatdev opened this issue Jul 17, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@codercatdev
Copy link
Contributor

🔖 Feature description

When calling createOAuth2Session there should be a way to pass in additional parameters. An example would be when trying to call auth0, I want to be able to pass in prompt=login to forcibly have the user login every time they call login. Currently when calling the authorization endpoint Auth0 sees that their is a user already active and automatically logged in.

🎤 Pitch

I would like to change
createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL;

in the sdk to take in a new parameter additionalQuery.

      await account.createOAuth2Session(
        "auth0",
        `${location.origin}/`,
        `${location.origin}/?login=failed`,
        []
      ); 

createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[], scopes?: string[], additionalQueries?: string[]): void | URL;

This would require a change within Appwrite's internals here

public function __construct(string $appId, string $appSecret, string $callback, array $state = [], array $scopes = [])

to include the

protected array $additionalQuery;
...
    public function __construct(string $appId, string $appSecret, string $callback, array $state = [], array $scopes = [], array $additionalQueries)
    {
        $this->appID = $appId;
        $this->appSecret = $appSecret;
        $this->callback = $callback;
        $this->state = $state;
        foreach ($scopes as $scope) {
            $this->addScope($scope);
        }
        foreach ($additionalQueries as $additionalQuery) {
            $this->addAdditionalQuery($additionalQuery);
        }
    }
...
    protected function addAdditionalQuery(string $query): OAuth2
    {
        // Add a query to the additionalQueries array if it isn't already present
        if (!\in_array($query, $this->additionalQueries)) {
            $this->additionalQueries[] = $query;
        }

        return $this;
    }
...

    /**
     * @return array
     */
    protected function getAdditionalQueries(): array
    {
        return $this->additionalQueries;
    }

Then you can make overrides like in Auth0

public function getLoginURL(): string

    public function getLoginURL(): string
    {
        return 'https://' . $this->getAuth0Domain() . '/authorize?' . \http_build_query([
            'client_id' => $this->appID,
            'redirect_uri' => $this->callback,
            'state' => \json_encode($this->state),
            'scope' => \implode(' ', $this->getScopes()),
            'response_type' => 'code'
            \implode(' ', $this->getAdditionalQueries()), //example `prompt=login`
        ]);
    }

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@codercatdev
Copy link
Contributor Author

codercatdev commented Jul 17, 2022

Right now I am solving this by hitting my logout window directly for the next login, which is not ideal having to pop user over to new window.

  const deleteSessions = async () => {
    if (!account) return null;
    try {
      await account.deleteSessions();
      setUser(null);
      setSessions(null);
      const wnd = window.open("https://codingcatdev.us.auth0.com/v2/logout");
      setTimeout(() => {
        wnd?.close();
      }, 1000);
    } catch (error) {
      throw error;
    }
  };

@stnguyen90 stnguyen90 added enhancement New feature or request and removed feature labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants