diff --git a/CHANGELOG.md b/CHANGELOG.md index 754bd12745..22f68865fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - #974, Fix RPC error when function has single OUT param - @steve-chavez - #1021, Reduce join size in allColumns for faster program start - @nextstopsun - #411, Remove the need for pk in &select for parent embed - @steve-chavez +- #1016, Fix anonymous requests when configured with jwt-aud - @ruslantalpa ## [0.4.3.0] - 2017-09-06 diff --git a/src/PostgREST/Auth.hs b/src/PostgREST/Auth.hs index dd93adb817..3f29fa4b04 100644 --- a/src/PostgREST/Auth.hs +++ b/src/PostgREST/Auth.hs @@ -39,7 +39,7 @@ data JWTAttempt = JWTInvalid JWTError of JWT claims. -} jwtClaims :: Maybe JWK -> Maybe StringOrURI -> LByteString -> IO JWTAttempt -jwtClaims _ Nothing "" = return $ JWTClaims M.empty +jwtClaims _ _ "" = return $ JWTClaims M.empty jwtClaims secret audience payload = case secret of Nothing -> return JWTMissingSecret diff --git a/src/PostgREST/Config.hs b/src/PostgREST/Config.hs index 9403af5afc..1f5a7ef269 100644 --- a/src/PostgREST/Config.hs +++ b/src/PostgREST/Config.hs @@ -151,6 +151,7 @@ readOptions = do Nothing -> pure Nothing -- no audience in config file Just aud -> case preview stringOrUri (aud :: String) of Nothing -> fail "Invalid Jwt audience. Check your configuration." + (Just "") -> pure Nothing aud' -> pure aud' coerceInt :: (Read i, Integral i) => Value -> Maybe i diff --git a/test/Feature/AudienceJwtSecretSpec.hs b/test/Feature/AudienceJwtSecretSpec.hs index 843ecf8558..35be4dd88f 100644 --- a/test/Feature/AudienceJwtSecretSpec.hs +++ b/test/Feature/AudienceJwtSecretSpec.hs @@ -41,4 +41,7 @@ spec = describe "test handling of aud claims in JWT" $ do -} let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjk5OTk5OTk5OTksInJvbGUiOiJwb3N0Z3Jlc3RfdGVzdF9hdXRob3IiLCJpZCI6Impkb2UifQ.Dpss-QoLYjec5OTsOaAc3FNVsSjA89wACoV-0ra3ClA" request methodGet "/authors_only" [auth] "" - `shouldRespondWith` 200 \ No newline at end of file + `shouldRespondWith` 200 + + it "requests without JWT token should work" $ + get "/has_count_column" `shouldRespondWith` 200 \ No newline at end of file