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

github enterprise oauth support #908

Closed
maxxedev opened this issue Mar 10, 2021 · 14 comments
Closed

github enterprise oauth support #908

maxxedev opened this issue Mar 10, 2021 · 14 comments
Labels

Comments

@maxxedev
Copy link

Hi,

How can remark42 be configured for github enterprise, where github is self-hosted at https://github.internal-network.company.com ? remark42 can authenticate with github only at the public URL: https://github.com ?

thanks

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

GitHub provider implemented by go-pkgz/auth, and the implementation is tiead to api.github.com

I'm not familiar enought with the github enterprise and don't have any instance to test it, but I would think on-premise instance may provide a similar api on the internal (self-hosted) url.

In order to support github enterprise provider, it should be added to go-pkgz/auth first. Integrating it into remark42 will be trivial.

@maxxedev
Copy link
Author

I tried by changing the oauth urls in backend/vendor/golang.org/x/oauth2/github/github.go but I see an error like this:

exchange failed - oauth2: server response missing access_token - 500 - 1.2.3.4-
/auth/github/callback?error=redirect_uri_mismatch
&error_description=The redirect_uri MUST match the registered callback URL for this application.
&error_uri=https://docs.github.com/enterprise/2.22/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch
&state=3083a3f5f18684cfa6caf42c34668bf711a76a53
[caused by auth/provider/oauth2.go:150 provider.Oauth2Handler.AuthHandler]

The URL does seem to match. Not sure what's going on.

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

Have you tried to change all 3 urls? 2 in oauth2.Endpoint and infoURL ?

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

btw, redirect_uri_mismatch usally means incorrect url in "Authorization callback URL" param set on github side

@maxxedev
Copy link
Author

maxxedev commented Mar 11, 2021

Fabulous. It works now. I was able to get past oauth problem by adjusting the ports bit in remark42 docker config:

- REMARK_PORT=<plain-port>
- REMARK_URL=https://internal-host:<secure-port>
- SSL_PORT=<secure-port>

And setting callback URL to this in github:

https://internal-host:<secure-port>/auth/github/callback

Thanks for the pointer about infoURL. I changed the value:
// in backend/vendor/github.com/go-pkgz/auth/provider/providers.go
https://github.internal/api/v3/user

Otherwise I saw "Invalid comment data" error message


I can post comments now. Avators don't work though. Any idea?

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

not sure what https://github.paypal.com/api/v3/user supposed to represent. This should be {internal-github}/api/v3/user url (or whatever ghe uses for this) and this URL is actually used to get info about user including avatar's url. It is mapped here to avatar_url fields from that /user response.

See https://docs.github.com/en/rest/reference/users#get-the-authenticated-user for more details

hope it helps.

P.S. If you make it work pls consider submitting PR to go-pkgz/auth

@maxxedev
Copy link
Author

I think avatars don't work for enterprise github requires login:

https://github.internal/avatars/u/1234

Compare that to public github:

https://avatars.githubusercontent.com/u/1234

@maxxedev
Copy link
Author

remark42 proxies the avatar url like this:

https://remark42-server/api/v1/avatar/1234.image

Is it possible to render raw URL? like:

https://github.internal/avatars/u/1234

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

it proxies images only after it can get one. This is, in fact, not a proxy, but a local copy of the avatar. This done intentionally because many providers don't like hotlinking

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

If your theory about "avatars don't work for enterprise github requires login" correct, this issue probably can be addressed by initiating authenticated call inside/around this mapping function. In theory, here we may know auth token and should be able to access protected resources

@maxxedev
Copy link
Author

Not sure about programmatic oauth users but for human users, authentication might be multi-factor authentication, so it might become complicated. I think hotlinking option would be an easy way out, where users are presumably authenticated in the browser already.

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

I think, at this point user already passed all auth handshakes, multifactor or not and programmatic access should be as easy as sending Authorization header

Hotlinking is a troublesome workaround. First of all, this is not that easy to do in the current auth model, and the second issue - most likely it will hit github limits. If some discussion has just 100 comments in (not that crazy size) it will try to hit ghe API with 100 image requests right away. Probably after the first hit it can be served from the cache but still unhealthy load.

@umputun
Copy link
Owner

umputun commented Mar 11, 2021

fyi: this is the place this infoURL got the hit https://github.com/go-pkgz/auth/blob/master/provider/oauth2.go#L155

as you can see it happens inside of AuthHandler and you should be able to get auth token from oauthClaims

@paskal
Copy link
Collaborator

paskal commented Jan 8, 2023

Resolving this issue in favour of go-pkgz/auth#75, feel free to reopen if I'm wrong.

@paskal paskal closed this as completed Jan 8, 2023
@paskal paskal added the backend label Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants