d4rkstar / kong-konga-keycloak

short tutorial to install kong, keycloak and konga in docker and test API authentication
281 stars 130 forks source link

CURL 302 found #3

Closed harsh4870 closed 4 years ago

harsh4870 commented 4 years ago

Thanks for the plugin it's working well in the browser as expectation user is being redirected everything working well.

but when i am sending curl request to service the plugin is on i am getting 302 found, however when plugin is not enabled getting a response.

please let me know if i am missing anything

RAWTKN=$(curl -s -X POST \
        -H "Content-Type: application/x-www-form-urlencoded" \
        -d "username=admin" \
        -d "password=admin" \
        -d 'grant_type=password' \
        -d "client_id=kong" \
        https://keycloak.harshmanvar.tk/auth/realms/master/protocol/openid-connect/token \
        |jq . )

export TKN=$(echo $RAWTKN | jq -r '.access_token')

#echo $TKN

curl -X GET "http://nginx.harshmanvar.tk/mock" \
-H "Accept: application/json" \
-H "Authorization: Bearer $TKN" 

if you can please help thanks in advance.

i am using nokia-oidc plugin.

d4rkstar commented 4 years ago

@harsh4870 it seems that you've not created a dedicated realm (you shouldn't use master realm) and in my example the kong client is reserved for api introspection and not for authentication purposes.

The 302 can be a redirect because of the bearer_only setting.

I would also suggest to restrict access to the administrator console on master realm: something like this: https://ios.developreference.com/article/15343370/Restricting+access+to+the+Keycloak+Admin+Console

harsh4870 commented 4 years ago

Thanks for reverting back..! You are right that was issue only after changing realm work like charm. Thanks once again..!