Skip to content

Conversation

joshsmith
Copy link
Contributor

@joshsmith joshsmith commented Nov 25, 2017

What's in this PR?

WIP. Haven't been able to figure it all out yet.

error_handler: CodeCorps.Auth.ErrorHandler

plug Guardian.Plug.VerifyHeader, realm: "Bearer"
plug Guardian.Plug.LoadResource, allow_blank: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't need to be allow_blank: true before but appears to need to be now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is accurate and will need to remain this way.

@@ -0,0 +1,11 @@
defmodule CodeCorps.Auth.ErrorHandler do
use CodeCorpsWeb, :controller
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appeared to be needed even though this isn't a controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure of a better way to handle this.

# send_resp(conn, 401, body) |> IO.inspect()
conn
|> put_status(401)
|> render(CodeCorpsWeb.TokenView, "401.json", message: to_string(type))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the message we want.

end

def resource_from_claims(%{"sub" => sub}), do: resource_from_sub(sub)
def resource_from_claims(_), do: {:error, :unknown_resource_type}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this can happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can happen, but the :error reason is probably not accurate. Maybe :missing_resource?

{:ok, auth_token, _claims} = updated_user |> Guardian.encode_and_sign(:token)
{:ok, %User{} = updated_user} <- user |> User.reset_password_changeset(params) |> Repo.update(),
{:ok, _auth_token} <- auth_token |> Repo.delete(),
{:ok, auth_token, _claims} = updated_user |> CodeCorps.Guardian.encode_and_sign()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have changed in ways I don't understand (i.e. not sure why we don't need :token as a param now).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it just changed quite a bit. This looks like it is the correct implementation now.

else
{:error, %Changeset{} = changeset} -> conn |> put_status(422) |> render(CodeCorpsWeb.ErrorView, :errors, data: changeset)
{:error, _} -> conn |> put_status(:not_found) |> render(CodeCorpsWeb.ErrorView, "404.json")
nil -> conn |> put_status(:not_found) |> render(CodeCorpsWeb.ErrorView, "404.json")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Letting FallbackController work.

@joshsmith
Copy link
Contributor Author

Going to merge since all seems working and seems not so critical. Happy to have follow-up issues based on anything that seems not quite great.

@joshsmith joshsmith merged commit d27b1ef into develop Nov 25, 2017
@joshsmith joshsmith deleted the update-guardian branch November 25, 2017 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant