Skip to content

Commit 180b299

Browse files
committed
Some fixes to 0.5.1
1 parent 4f0467d commit 180b299

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Require ExOauth2Provider v0.5.1
66
* Pass configuration to all ExOauth2Provider methods
7+
* Removed `ExOauth2Provider.Config.native_redirect_uri/1` call in templates in favor of using assigns
78

89
## v0.5.0 (2019-05-08)
910

lib/phoenix_oauth2_provider/controller.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ defmodule PhoenixOauth2Provider.Controller do
7676

7777
@doc false
7878
def __action_params__(conn, config, :api), do: [conn, conn.params, config]
79-
def __action_params__(conn, config, _any), do: [conn, conn.params, current_resource_owner(conn), config]
79+
def __action_params__(conn, config, _any), do: [conn, conn.params, current_resource_owner(conn, config), config]
8080

81-
defp current_resource_owner(conn) do
82-
resource_owner_key = Config.current_resource_owner([])
81+
defp current_resource_owner(conn, config) do
82+
resource_owner_key = Config.current_resource_owner(config)
8383

8484
case Map.get(conn.assigns, resource_owner_key) do
8585
nil -> raise "Resource owner was not found with :#{resource_owner_key} assigns"

lib/phoenix_oauth2_provider/controllers/application_controller.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ defmodule PhoenixOauth2Provider.ApplicationController do
55
alias ExOauth2Provider.Applications
66
alias Plug.Conn
77

8+
plug :assign_native_redirect_uri when action in [:new, :create, :edit, :update]
9+
810
@spec index(Conn.t(), map(), map(), keyword()) :: Conn.t()
911
def index(conn, _params, resource_owner, config) do
1012
applications = Applications.get_applications_for(resource_owner, config)
@@ -49,7 +51,7 @@ defmodule PhoenixOauth2Provider.ApplicationController do
4951
application = get_application_for!(resource_owner, uid, config)
5052
changeset = Applications.change_application(application, %{}, config)
5153

52-
render(conn, "edit.html", application: application, changeset: changeset)
54+
render(conn, "edit.html", changeset: changeset)
5355
end
5456

5557
@spec update(Conn.t(), map(), map(), keyword()) :: Conn.t()
@@ -63,7 +65,7 @@ defmodule PhoenixOauth2Provider.ApplicationController do
6365
|> redirect(to: Routes.oauth_application_path(conn, :show, application))
6466

6567
{:error, %Ecto.Changeset{} = changeset} ->
66-
render(conn, "edit.html", application: application, changeset: changeset)
68+
render(conn, "edit.html", changeset: changeset)
6769
end
6870
end
6971

@@ -82,4 +84,10 @@ defmodule PhoenixOauth2Provider.ApplicationController do
8284
defp get_application_for!(resource_owner, uid, config) do
8385
Applications.get_application_for!(resource_owner, uid, config)
8486
end
87+
88+
defp assign_native_redirect_uri(conn, _opts) do
89+
native_redirect_uri = ExOauth2Provider.Config.native_redirect_uri(conn.private[:phoenix_oauth2_provider_config])
90+
91+
Conn.assign(conn, :native_redirect_uri, native_redirect_uri)
92+
end
8593
end

lib/phoenix_oauth2_provider/views/application_view.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ defmodule PhoenixOauth2Provider.ApplicationView do
2727
<%%= textarea f, :redirect_uri %>
2828
<%%= error_tag f, :redirect_uri %>
2929
<span class="help-block">Use one line per URI</span>
30-
<%%= unless is_nil(ExOauth2Provider.Config.native_redirect_uri([])) do %>
30+
<%%= if is_nil(@native_redirect_uri) do %>
3131
<span class="help-block">
32-
Use <code><%%= ExOauth2Provider.Config.native_redirect_uri([]) %></code> for local tests
32+
Use <code><%%= @native_redirect_uri %></code> for local tests
3333
</span>
3434
<%% end %>
3535

0 commit comments

Comments
 (0)