ccrockett / omniauth-keycloak

Keycloak Strategy for OmniAuth.
MIT License
53 stars 42 forks source link

No route matches [POST] "/auth/keycloak_openid" #15

Closed andreas-it-dev closed 2 years ago

andreas-it-dev commented 3 years ago

Hi, first of all thanks for this gem.

I just create a new rails 6.1 project and first thing to me is to get auth working.. so there is nothing installed except this gem plus its dependencies..

i have configured this initializer:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :keycloak_openid, 'xxxCLIENTxxx', 'xxxKEYxxx',
           client_options: {site: 'https://auth.xxxDOMAINxxx.com', realm: 'xxxREALMxxx'}
end

this route:

post '/auth/:provider/callback', to: 'sessions#create'

and just for testing a quick and dirty

<%= button_to 'Sign In', '/auth/keycloak_openid' %>

to get the ball rolling.. i click on it and get this No route matches [POST] "/auth/keycloak_openid"error.

however, Omniauth is present and its config suggests the keycloak_openid provider is too:

image

i also gave auth/keycloak a shot (yeah, proly made no sense, but just in case)... - same thing

idk what i did wrong here, maybe its a bug (with rails 6.1)..(?)

andreas-it-dev commented 3 years ago

fwiw, i added the omniauth-twitter gem and /auth/twitter is happily responding..

so, we could rule out a general omniauth issue, probably

i also tried a rails 6.0.4 fresh app real quick.. same error

andreas-it-dev commented 3 years ago

did some quick look and fired up the debugger.. it doesnt even break in the setup_phase method..(?)

image

frenesim commented 3 years ago

I'm having the same problem here. Have you found what should be the endpoint?

andreas-it-dev commented 3 years ago

nope, i put this on the stack hoping for the author to respond, eventually..

frenesim commented 3 years ago

Hey @awunder. I overcome this by setting the option name as per in the omniauth strategy docs. I endup to add this option while setting the provider, like this:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :keycloak_openid, 'xxxCLIENTxxx', 'xxxKEYxxx',
           client_options: {site: 'https://auth.xxxDOMAINxxx.com', realm: 'xxxREALMxxx'},
           name: "what_ever"
end

Then I successfully request via POST

<%= button_to 'Sign In', '/auth/what_ever' %>

Hope it helps.

I think this info would be helpful in READMME

andreas-it-dev commented 3 years ago

hey @frenesim thank you so much for this.. this indeed helped a lot!

andreas-it-dev commented 3 years ago

i had to deal with some other stuff so i couldnt really test this out..

now i did, but the funny thing is, that now the auth callback url doesnt work..

i gave it a name via

image

and now the redirect fails with a No route matches [GET] "/auth/ofwd/callback"

@frenesim did this work for you?

andreas-it-dev commented 3 years ago

please disregard, i commented out the callback route :facepalm: