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

Wrong method to fetch token for openID connect #2421

Closed
2 of 7 tasks
Lichtjaeger opened this issue Aug 29, 2017 · 21 comments
Closed
2 of 7 tasks

Wrong method to fetch token for openID connect #2421

Lichtjaeger opened this issue Aug 29, 2017 · 21 comments
Labels
type/question Issue needs no code to be fixed, only a description on how to fix it yourself.

Comments

@Lichtjaeger
Copy link

  • Gitea version (or commit ref): 1.2.0-rc1
  • Git version: 2.14.1
  • Operating system: Windows 10
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log:
2017/08/29 10:40:12 [I] Log Mode: File(Info)
2017/08/29 10:40:12 [I] XORM Log Mode: File(Info)
2017/08/29 10:40:12 [I] Cache Service Enabled
2017/08/29 10:40:12 [I] Session Service Enabled
2017/08/29 10:40:13 [I] Git Version: 2.14.1
2017/08/29 10:40:13 [I] SQLite3 Supported
2017/08/29 10:40:13 [I] Run Mode: Production
2017/08/29 10:40:13 [I] Listen: http://0.0.0.0:3000
2017/08/29 10:40:35 [...routers/user/auth.go:409 handleOAuth2SignIn()] [E] UserSignIn: oauth2: cannot fetch token: 405 Method Not Allowed
Response: {"error":"invalid_request","error_description":"method not allowed"}

Description

Hi, I try to implement an openID connect Login with oidc-provider for Node.js.

But I get "method not allowed" errors if I test this solution. I opened an Issue at the provider page ( panva/node-oidc-provider#150 ) and the answer was, that the client used the wrong method to request the token.

@panva
Copy link

panva commented Aug 29, 2017

Hi, I am maintaining oidc-provider.

method not allowed is returned in cases where a route only responds to certain HTTP methods(verbs), in this case a POST for a token_endpoint, but other method is encountered.

@lunny
Copy link
Member

lunny commented Aug 29, 2017

From the log, it seems you are try to use OAuth2 login but not OpenID connect ?

@panva
Copy link

panva commented Aug 29, 2017

From an authorization_code flow perspective the two are the same (only in OIDC you must request the openid scope). Either way, the token_endpoint request must use a POST, does it?

@Lichtjaeger
Copy link
Author

Here are my settings:
schnappschuss_083017_071532_am

And the "/.well-known/openid-configuration.json":
openid-configuration.zip

@lunny lunny added the type/question Issue needs no code to be fixed, only a description on how to fix it yourself. label Aug 30, 2017
@Lichtjaeger
Copy link
Author

No improvement in Gitea v1.2.0-rc2.

@lunny
Copy link
Member

lunny commented Sep 7, 2017

@strk maybe you can see this?

@Lichtjaeger
Copy link
Author

No improvement in Gitea v1.2.0-rc3.

@Lichtjaeger
Copy link
Author

No improvement in Gitea v1.2.0. #618 still doesn't work for me.

@Lichtjaeger
Copy link
Author

No improvement in Gitea v1.3.0-rc1.

@Lichtjaeger
Copy link
Author

No improvement in Gitea v1.3.2.

@strk please state something.

@strk
Copy link
Member

strk commented Jan 3, 2018

Sorry but I'm not involved in OpenID Connect consumer code at all. I did OpenID-2.0 one. The OpenID Connect code, as far as I can tell, was added by @willemvd in commit 950f2e2 via #1010

Willem, can you help here ?

@strk
Copy link
Member

strk commented Jan 3, 2018

@Lichtjaeger re "#618 still doesn't work for me." you mean you don't haven an OpenID-2.0 server to use against, right ? Or file a separate issue if OpenID-2.0 is also not working for you, against a valid server.

@Lichtjaeger
Copy link
Author

Lichtjaeger commented Jan 3, 2018

you mean you don't haven an OpenID-2.0 server to use against, right ? Or file a separate issue if OpenID-2.0 is also not working for you, against a valid server.

Sorry, I was looking for a reference to my problem and only found this. Yes, I don't have an OpenID-2.0 Server. I tried to use OpenID connect from the start.

@willemvd
Copy link
Contributor

@Lichtjaeger have you also configured the yammer provider? This error message is only displayed when using the yammer provider (https://github.com/markbates/goth/search?q=%22cannot+fetch+token%22&type=)
Looks like the error message returned from the library is not correct

@Lichtjaeger
Copy link
Author

@willemvd I don't know anything about yammer provider. But the message ("cannot fetch token: 405 Method Not Allowed") is correct. I use the oidc-provider for NodeJS from @panva. You can also read the error message I've got from the provider at panva/node-oidc-provider#150.

@Lichtjaeger
Copy link
Author

I eventually found the problem. In my NginX loadbalancer I used return 301 https://$server_name$request_uri; to force SSL. This changed the POST request into a GET request.

Now I use return 308 https://$server_name$request_uri;, but I get some other errors.

Requesting the token without https results in:

2018/01/25 08:35:22 [...routers/user/auth.go:411 handleOAuth2SignIn()] [E] UserSignIn: oauth2: cannot fetch token: 308 
Response: https://auth.gbn.web/token

Requesting without forcing SSL results in:

2018/01/25 09:14:49 [...routers/user/auth.go:411 handleOAuth2SignIn()] [E] UserSignIn: userinfo response did not contain a 'sub' claim: map[string]interface {}{"sub":57}

@Lichtjaeger
Copy link
Author

The error for 308 statuses is solved thru reconfiguration of the /.well-known/openid-configuration endpoint.

But there is still the error with the "sub" claim. The debug output of the oidc-provider is:

oidc-provider:userinfo uuid=fbb7df8c-1cfa-4dbd-a896-da077ffe4eb4 content-type=application/json response={ sub: 57 }

@Lichtjaeger
Copy link
Author

OK, I changed the type of the "sub" from number to string and now it works.

@strk
Copy link
Member

strk commented Jan 29, 2018 via email

@Lichtjaeger
Copy link
Author

I can try to make time for it.

PS: I have a suggestion for improvement. oidc provides a lot of other claims (for example email, family_name, given_name, name, preferred_username). The discovery result can tell you if they are available. You could use them to autofill the registration form.

@strk
Copy link
Member

strk commented Jan 29, 2018 via email

@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/question Issue needs no code to be fixed, only a description on how to fix it yourself.
Projects
None yet
Development

No branches or pull requests

5 participants