{"id":26913651,"url":"https://github.com/worldline-go/auth","last_synced_at":"2025-04-01T16:38:24.816Z","repository":{"id":65817018,"uuid":"580018481","full_name":"worldline-go/auth","owner":"worldline-go","description":"authenticate and authorization library","archived":false,"fork":false,"pushed_at":"2024-01-19T13:31:42.000Z","size":186,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-06-22T13:14:47.215Z","etag":null,"topics":["authentication","keycloak","oauth2"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/worldline-go.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-19T14:14:04.000Z","updated_at":"2023-03-01T16:02:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9f929cd-dbd0-4e91-aa03-5401ecd71cdc","html_url":"https://github.com/worldline-go/auth","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"ec0fb0d7a7a466d96d076bcfb453c03b8e931401"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worldline-go%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worldline-go%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worldline-go%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worldline-go%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worldline-go","download_url":"https://codeload.github.com/worldline-go/auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246671915,"owners_count":20815290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","keycloak","oauth2"],"created_at":"2025-04-01T16:38:24.232Z","updated_at":"2025-04-01T16:38:24.809Z","avatar_url":"https://github.com/worldline-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auth\n\nAuthenticating and authorizing client/server applications.\n\n## Usage\n\n```sh\ngo get github.com/worldline-go/auth\n```\n\nCheck http example: [example/http](example/http)\n\n## Packages\n\n__-__ __echo middleware__ -\u003e [pkg/authecho](pkg/authecho/README.md)\n\n### Client\n\nClient is usefull to send request with oauth2 token.\n\nFirst set a provider.\n\n```go\nvar providerClient = auth.Provider{\n\tKeycloak: \u0026providers.KeyCloak{\n\t\tClientID:     \"test\",\n\t\tClientSecret: \"my_client_secret\",\n        // Keycloak server url\n\t\tBaseURL:      \"http://localhost:8080\",\n\t\tRealm:        \"finops\",\n        // Scopes is optional\n\t\tScopes:       []string{\"openid\", \"profile\", \"email\", \"offline_access\"},\n\t},\n}\n```\n\nThen when you create a http.Client you can use the oauth2 transport.\n\n```go\nprovider := providerClient.ActiveProvider()\nif == nil {\n\treturn fmt.Errorf(\"no active provider\")\n}\n\nroundTripper, err := provider.RoundTripper(ctx, http.DefaultTransport)\nif err != nil {\n\treturn fmt.Errorf(\"creating round tripper: %w\", err)\n}\n\nclient := \u0026http.Client{\n    Transport: roundTripper,\n}\n```\n\nNow you can make request with this client.\n\n### Server\n\nCheck the token in the request. Just need to url of keycloak server and the realm.\n\n```go\nvar providerServer = auth.Provider{\n\tKeycloak: \u0026providers.KeyCloak{\n        // Keycloak server url\n\t\tBaseURL: \"http://localhost:8080\",\n\t\tRealm:   \"finops\",\n\t},\n}\n```\n\nThen you can check the token in the request.\n\nThis is the http based, very simple function but check the our [echo middleware](middlewares/authecho/README.md) to much more advanced operations.\n\n```go\nprovider := providerServer.ActiveProvider()\nif provider == nil {\n\treturn fmt.Errorf(\"no active provider\")\n}\n\nkeyFunc, err := provider.JWTKeyFunc(auth.WithContext(ctx))\nif err != nil {\n\treturn fmt.Errorf(\"creating parser: %w\", err)\n}\n\n// if you don't use the context cancelation, you can use this\n// defer keyFunc.EndBackground()\n\n// Check the token in the request\nclaimsValue := claims.Custom{}\ntoken, err := keyFunc.Parser(tokenToCheck, \u0026claimsValue)\nif err != nil {\n    return fmt.Errorf(\"token 👎: %w\", err)\n}\n```\n\n## Redirection Flow\n\nWhen enabled redirection in the middleware, the user will be redirected to the oauth2 login page.\n\nThis is not a standard flow and we can change update it any time.  \nCode for echo middleware is [here](middlewares/authecho/README.md).\n\n![Redirection Flow](docs/assets/redirection-flow.svg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworldline-go%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworldline-go%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworldline-go%2Fauth/lists"}