matrix-org / go-neb

Extensible matrix bot written in Go
Apache License 2.0
284 stars 91 forks source link

Can we get a simple tutorial for github webhooks? #314

Open xxxserxxx opened 4 years ago

xxxserxxx commented 4 years ago

I'm getting stuck at authentication. Can somebody write a simple tutorial using curl? The format of the JSON is opaque; there's no json tags on the structs, so reading the code isn't easy short of really parsing all of the logic.

util% curl -X POST localhost:4050/admin/configureAuthRealm --data-binary '{
"Id": "github_realm",
"Type": "github",
"Config": {}
}'
{"ID":"github_realm","Type":"github","OldConfig":null,"NewConfig":{"ClientSecret":"","ClientID":"","StarterLink":""}}%

so that looked like it worked. Then trying to get a session (obfuscated the secrets):

curl -X POST localhost:4050/admin/requestAuthSession --data-binary '{
        "RealmId": "github_realm",
        "UserID": "@foo:matrix.my.server",
        "Config": {
                "AccessToken": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                "Scopes": ["admin:org_hook","admin:repo_hook","repo","user"]
        }
}'
{"URL":"https://github.com/login/oauth/authorize?client_id=\u0026client_secret=\u0026redirect_uri=http%3A%2F%2Flocalhost%3A4050%2Frealms%2Fredirects%2FZ20000XXlYWxt\u0026scope=admin%3Arepo_hook%2Cadmin%3Aorg_hook%2Crepo\u0026state=fffffffffffffffffffffffff"}

so that looked like it worked. Then trying to create the service:

util% curl -X POST localhost:4050/admin/configureService '{
        "Id": "github_webhook_service",
        "Type": "github-webhook",
        "UserID": "@foo:matrix.my.server",
        "Config": {
                "RealmID": "github_realm",
                "ClientUserID": "@foo:matrix.my.server",
                "Rooms": {
                        "!gotop:matrix.org": {
                                "Repos": {
                                        "matrix-org/synapse": {
                                                "Events": ["push", "issues", "pull_request", "issue_comment"]
                                        }
                                }
                        }
                }
        }
}'
{"message":"Failed to register service: User @foo:matrix.my.server does not have a Github auth session with realm github_realm"}

Failure. Even a simple walk-through would be useful.

xxxserxxx commented 4 years ago

Incidentally: the service is exposed and accessible; I re-ran the request-auth command with the external URL, and got back a similar response but with a different callback URL. When I try to call that URL from a web browser, github returns a 404.

pratikbin commented 2 years ago

Use yaml as config.