{"id":26462919,"url":"https://github.com/clerk/clerk-sdk-go","last_synced_at":"2025-03-19T06:26:12.004Z","repository":{"id":41395562,"uuid":"326961447","full_name":"clerk/clerk-sdk-go","owner":"clerk","description":"Access the Clerk Backend API from Go","archived":false,"fork":false,"pushed_at":"2024-07-09T10:19:37.000Z","size":508,"stargazers_count":73,"open_issues_count":6,"forks_count":13,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-07-10T14:16:40.432Z","etag":null,"topics":["authentication","authentication-middleware","clerk-sdk","sdk","sdk-go"],"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/clerk.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-05T10:18:00.000Z","updated_at":"2024-07-22T07:31:54.707Z","dependencies_parsed_at":"2023-09-26T12:45:57.624Z","dependency_job_id":"b30e7b75-4eeb-4679-b61a-0af778a555e4","html_url":"https://github.com/clerk/clerk-sdk-go","commit_stats":{"total_commits":194,"total_committers":15,"mean_commits":"12.933333333333334","dds":0.4639175257731959,"last_synced_commit":"374f5f768e371618450b9fd3505460cbb0cfe69e"},"previous_names":["clerkinc/clerk_server_sdk_go","clerk/clerk-sdk-go","clerkinc/clerk-sdk-go"],"tags_count":108,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fclerk-sdk-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fclerk-sdk-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fclerk-sdk-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clerk%2Fclerk-sdk-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clerk","download_url":"https://codeload.github.com/clerk/clerk-sdk-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244367551,"owners_count":20441910,"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","authentication-middleware","clerk-sdk","sdk","sdk-go"],"created_at":"2025-03-19T06:26:11.513Z","updated_at":"2025-03-19T06:26:11.996Z","avatar_url":"https://github.com/clerk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.clerk.com/?utm_source=github\u0026utm_medium=starter_repos\u0026utm_campaign=sdk_go\" target=\"_blank\" align=\"center\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./docs/clerk-logo-dark.png\"\u003e\n      \u003cimg src=\"./docs/clerk-logo-light.png\" height=\"64\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n\u003c/p\u003e\n\n# Clerk Go SDK\n\nGo client library for accessing the [Clerk Backend API](https://clerk.com/docs/reference/backend-api).\n\n[![GoDoc](https://img.shields.io/static/v1?label=godoc\u0026message=reference\u0026color=blue)](https://pkg.go.dev/github.com/clerkinc/clerk-sdk-go/clerk)\n[![Test Status](https://github.com/clerkinc/clerk-sdk-go/workflows/tests/badge.svg)](https://github.com/clerkinc/clerk-sdk-go/actions?query=workflow%3Atests)\n\n[![chat on Discord](https://img.shields.io/discord/856971667393609759.svg?logo=discord)](https://discord.com/invite/b5rXHjAg7A)\n[![documentation](https://img.shields.io/badge/documentation-clerk-green.svg)](https://clerk.com/docs)\n[![twitter](https://img.shields.io/twitter/follow/ClerkDev?style=social)](https://twitter.com/intent/follow?screen_name=ClerkDev)\n\n---\n\n**Clerk is Hiring!**\n\nWould you like to work on Open Source software and help maintain this repository? [Apply today!](https://jobs.ashbyhq.com/clerk)\n\n---\n\n## Usage\n\nFirst, add the Clerk SDK as a dependency to your project.\n\n```\n$ go get github.com/clerkinc/clerk-sdk-go\n```\n\nAdd the following import to your Go files.\n\n```go\nimport \"github.com/clerkinc/clerk-sdk-go/clerk\"\n```\n\nNow, you can create a Clerk client by calling the `clerk.NewClient` function.\nThis function requires your Clerk API key.\nYou can get this from the dashboard of your Clerk application.\n\nOnce you have a client, you can use the various services to access different parts of the API.\n\n```go\napiKey := os.Getenv(\"CLERK_API_KEY\")\n\nclient, err := clerk.NewClient(apiKey)\nif err != nil {\n    // handle error\n}\n\n// List all users for current application\nusers, err := client.Users().ListAll(clerk.ListAllUsersParams{})\n```\n\nThe services exposed in the `clerk.Client` divide the API into logical chunks and\nfollow the same structure that can be found in the [Backend API documentation](https://clerk.com/docs/reference/backend-api).\n\nFor more examples on how to use the client, refer to the [examples](https://github.com/clerkinc/clerk-sdk-go/tree/main/examples/operations)\n\n### Options\n\nThe SDK `Client` constructor can also accept additional options defined [here](https://github.com/clerk/clerk-sdk-go/blob/main/clerk/clerk_options.go).\n\nA common use case is injecting your own [`http.Client` object](https://pkg.go.dev/net/http#Client) for testing or automatically retrying requests.\nAn example using [go-retryablehttp](https://github.com/hashicorp/go-retryablehttp/#getting-a-stdlib-httpclient-with-retries) is shown below:\n\n```go\nretryClient := retryablehttp.NewClient()\nretryClient.RetryMax = 5\nstandardClient := retryClient.StandardClient() // *http.Client\n\nclerkSDKClient := clerk.NewClient(token, clerk.WithHTTPClient(standardClient))\n```\n\n## Middleware\n\nThe SDK provides the [`WithSessionV2`](https://pkg.go.dev/github.com/clerkinc/clerk-sdk-go/v2/clerk#WithSessionV2) middleware that injects the active session into the request's context.\n\nThe active session's claims can then be accessed using [`SessionFromContext`](https://pkg.go.dev/github.com/clerkinc/clerk-sdk-go/v2/clerk#SessionFromContext).\n\n```go\nmux := http.NewServeMux()\ninjectActiveSession := clerk.WithSessionV2(client)\nmux.Handle(\"/your-endpoint\", injectActiveSession(yourEndpointHandler))\n```\n\nAdditionally, there's [`RequireSessionV2`](https://pkg.go.dev/github.com/clerkinc/clerk-sdk-go/v2/clerk#RequireSessionV2) that will halt the request and respond with 403 if the user is not authenticated. This can be used to restrict access to certain routes unless the user is authenticated.\n\nFor more info on how to use the middleware, refer to the\n[example](https://github.com/clerkinc/clerk-sdk-go/tree/main/examples/middleware).\n\n### Additional options\n\nThe middleware supports the following options:\n\n- clerk.WithAuthorizedParty() to set the authorized parties to check against the azp claim of the token\n- clerk.WithLeeway() to set a custom leeway that gives some extra time to the token to accommodate for clock skew\n- clerk.WithJWTVerificationKey() to set the JWK to use for verifying tokens without the need to fetch or cache any JWKs at runtime\n- clerk.WithCustomClaims() to pass a type (e.g. struct), which will be populated with the token claims based on json tags.\n- clerk.WithSatelliteDomain() to skip the JWT token's \"iss\" claim verification.\n- clerk.WithProxyURL() to verify the JWT token's \"iss\" claim against the proxy url.\n\nFor example\n\n```golang\ncustomClaims := myCustomClaimsStruct{}\n\nclerk.WithSessionV2(\n\tclerkClient,\n\tclerk.WithAuthorizedParty(\"my-authorized-party\"),\n\tclerk.WithLeeway(5 * time.Second),\n\tclerk.WithCustomClaims(\u0026customClaims),\n\tclerk.WithSatelliteDomain(true),\n\tclerk.WithProxyURL(\"https://example.com/__clerk\"),\n\t)\n```\n\n## License\n\nThis SDK is licensed under the MIT license found in the [LICENSE](./LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclerk%2Fclerk-sdk-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclerk%2Fclerk-sdk-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclerk%2Fclerk-sdk-go/lists"}