venveo / craft-oauthclient

A free to use OAuth 2.0 Client helper for Craft 3 developers
MIT License
9 stars 3 forks source link

Adds the option to send the redirect URL via context #29

Closed kennethormandy closed 4 years ago

kennethormandy commented 4 years ago

I was looking for a way to set the redirect after the OAuth flow when making the link as a link, rather than a form submission. The place I’m adding the link is already inside a form in the Craft control panel, similar to the “+” add Token button in the plugin UI, so it isn’t practical to make it a form.

Would adding the redirect URL to the context + this PR, be a reasonable way to add that functionality?

{% set context = {
  redirect: "https://example.com"
} %}

<a href="{{ app.getRedirectUrl(context) }}">Connect</a>

Or is it intentionally only done via a POST request right now?

Alternatively, could this be done in the EVENT_GET_URL_OPTIONS event?

Another option that might solve it for me would be to make the default redirect value the page you were originally on, rather than oauthclient/apps.

I can open a different PR if any of those other approaches sound more appealing to you, or maybe I am missing something. Thanks very much!

Mosnar commented 4 years ago

This looks great to me actually! Thank you!

Mosnar commented 4 years ago

Actually, I may tweak this just a little.

Mosnar commented 4 years ago

@kennethormandy Okay, I just released 2.1.7 with the ability to do this. I went a different route than what this PR proposed, so make sure you check the docs. I made the following changes:

Updated the docs with examples here: https://github.com/venveo/craft-oauthclient#modifying-the-authentication-flow-conditionally

kennethormandy commented 4 years ago

This is working well for me, thanks so much!