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

Reimplement header auth #87

Open
ilyakooo0 opened this issue Aug 31, 2021 · 0 comments
Open

Reimplement header auth #87

ilyakooo0 opened this issue Aug 31, 2021 · 0 comments

Comments

@ilyakooo0
Copy link
Member

Currently, we abuse the servant-auth library to provide authentication for octo CLI.

The authentication is very simple: we just check the Authorization header in every request for equality.

Using servant-auth for this is overkill and the library doesn't handle the use case very well – it expects the payload to be JSON-encoded, etc.

Additionally, it has a large dependency footprint that we can avoid.

data AuthHeaderAuth

Auth '[AuthHeaderAuth] () :> "api" :> "v1"

newtype AuthHeader = AuthHeader ByteString
instance IsAuth AuthHeaderAuth () where
type AuthArgs AuthHeaderAuth = '[AuthHeader]
runAuth _ _ (AuthHeader h) = AuthCheck $ \req ->
pure $ case lookup "Authorization" $ requestHeaders req of
Just v | v == h -> Authenticated ()
_ -> Indefinite
deriving anyclass instance ToJWT ()

class IsAuth a where
data AuthContext a
applyAuth :: AuthContext a -> Request -> Request
instance (IsAuth a, HasClient m api) => HasClient m (Auth '[a] x :> api) where
type Client m (Auth '[a] x :> api) = AuthContext a -> Client m api
clientWithRoute pm Proxy req val =
clientWithRoute pm (Proxy :: Proxy api) (applyAuth val req)
hoistClientMonad pm _ f cl = hoistClientMonad pm (Proxy :: Proxy api) f . cl
instance IsAuth AuthHeaderAuth where
data AuthContext AuthHeaderAuth = AuthHeaderAuthCtx String
applyAuth (AuthHeaderAuthCtx h) req = addHeader "Authorization" h req


The task is to remove the servant-auth dependency while keeping the current behavior. The functionality seems simple enough that we can implement it without any additional dependencies. But, if an existing library arises that fits the task well, I am not against using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants