{"id":13600225,"url":"https://github.com/casdoor/casdoor-go-sdk","last_synced_at":"2025-04-08T20:19:20.440Z","repository":{"id":40447520,"uuid":"372013137","full_name":"casdoor/casdoor-go-sdk","owner":"casdoor","description":"Go client SDK for Casdoor","archived":false,"fork":false,"pushed_at":"2025-03-08T11:30:38.000Z","size":268,"stargazers_count":98,"open_issues_count":3,"forks_count":76,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T18:20:31.927Z","etag":null,"topics":["auth","authentication","authn","casdoor","go","golang","jwt","oauth","oidc","sdk"],"latest_commit_sha":null,"homepage":"https://github.com/casdoor/casdoor","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casdoor.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":"2021-05-29T15:53:56.000Z","updated_at":"2025-03-30T02:59:51.000Z","dependencies_parsed_at":"2023-02-01T06:45:45.228Z","dependency_job_id":"5d8a63d6-75ec-4685-8a54-ab4242716b8d","html_url":"https://github.com/casdoor/casdoor-go-sdk","commit_stats":{"total_commits":129,"total_committers":34,"mean_commits":"3.7941176470588234","dds":0.5891472868217054,"last_synced_commit":"471f21b7ea0d5c823abe554ccd2d11447d6cceb5"},"previous_names":[],"tags_count":110,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casdoor%2Fcasdoor-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casdoor","download_url":"https://codeload.github.com/casdoor/casdoor-go-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247919005,"owners_count":21018046,"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":["auth","authentication","authn","casdoor","go","golang","jwt","oauth","oidc","sdk"],"created_at":"2024-08-01T18:00:32.800Z","updated_at":"2025-04-08T20:19:20.421Z","avatar_url":"https://github.com/casdoor.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# casdoor-go-sdk\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#badge\"\u003e\n    \u003cimg alt=\"semantic-release\" src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/casdoor/casdoor-go-sdk/actions/workflows/ci.yml\"\u003e\n    \u003cimg alt=\"GitHub Workflow Status (branch)\" src=\"https://img.shields.io/github/actions/workflow/status/casdoor/casdoor-go-sdk/ci.yml?branch=master\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/casdoor/casdoor-go-sdk/releases/latest\"\u003e\n    \u003cimg alt=\"GitHub Release\" src=\"https://img.shields.io/github/v/release/casdoor/casdoor-go-sdk.svg\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://goreportcard.com/report/github.com/casdoor/casdoor-go-sdk\"\u003e\n    \u003cimg alt=\"Go Report Card\" src=\"https://goreportcard.com/badge/github.com/casdoor/casdoor-go-sdk?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/casdoor/casdoor-go-sdk/blob/master/LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/casdoor/casdoor-go-sdk?style=flat-square\" alt=\"license\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/casdoor/casdoor-go-sdk/issues\"\u003e\n    \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/casdoor/casdoor-go-sdk?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"#\"\u003e\n    \u003cimg alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/casdoor/casdoor-go-sdk?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/casdoor/casdoor-go-sdk/network\"\u003e\n    \u003cimg alt=\"GitHub forks\" src=\"https://img.shields.io/github/forks/casdoor/casdoor-go-sdk?style=flat-square\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://discord.gg/5rPsrAzK7S\"\u003e\n    \u003cimg alt=\"Casdoor\" src=\"https://img.shields.io/discord/1022748306096537660?style=flat-square\u0026logo=discord\u0026label=discord\u0026color=5865F2\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\nThis is Casdoor's SDK for Go, which will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch.\n\nCasdoor Go SDK is very simple to use. We will show you the steps below.\n\n## Step 1. Install and Import\n\nFirst in your go project, just need to run:\n\n```bash\ngo get github.com/casdoor/casdoor-go-sdk@latest\n```\n\nand import this when you need:\n\n```go\nimport \"github.com/casdoor/casdoor-go-sdk/casdoorsdk\"\n```\n\n## Step 2. Init\n\nInitialization requires 6 parameters, which are all string type:\n\n| Name (in order)  | Must | Description                                         |\n|------------------|------|-----------------------------------------------------|\n| endpoint         | Yes  | Casdoor server URL, such as `http://localhost:8000` |\n| clientId         | Yes  | Application.clientId                                |\n| clientSecret     | Yes  | Application.clientSecret                            |\n| certificate      | Yes  | x509 certificate content of Application.cert        |\n| organizationName | Yes  | Application.organization                            |\n| applicationName  | Yes  | Application.applicationName                         |\n\n### You can either initialize the SDK with global config\n\n```go\nfunc InitConfig(endpoint string, clientId string, clientSecret string, certificate string, organizationName string, applicationName string)\n\n// Then call sdk functions like\ncasdoorsdk.GetUsers()\n```\n\n### or create a custom Client with unique config\n\n```go\nclient := casdoorsdk.NewClient(endpoint, clientId, clientSecret, certificate, organizationName, applicationName)\nclient.GetUsers()\n```\n\n## Step 3. Get token and parse\n\nAfter casdoor verification passed, it will be redirected to your application with code and state, like `https://forum.casbin.com?code=xxx\u0026state=yyyy`.\n\nYour web application can get the `code`,`state` and call `GetOAuthToken(code, state)`, then parse out jwt token.\n\nThe general process is as follows:\n\n```go\ntoken, err := casdoorsdk.GetOAuthToken(code, state)\nif err != nil {\n\tpanic(err)\n}\n\nclaims, err := casdoorsdk.ParseJwtToken(token.AccessToken)\nif err != nil {\n\tpanic(err)\n}\n\nclaims.AccessToken = token.AccessToken\n```\n\n## Step 4. Set Session in your app\n\n`auth.Claims` contains the basic information about the user provided by casdoor, you can use it as a keyword to set the session in your application, like this:\n\n```go\ndata, _ := json.Marshal(claims)\nc.setSession(\"user\", data)\n```\n\n## Step 5. Interact with the users\n\nCasdoor-go-sdk support basic user operations, like:\n\n- `GetUser(name string)`, get one user by user name.\n- `GetUsers()`, get all users.\n- `UpdateUser(casdoorsdk.User)/AddUser(casdoorsdk.User)/DeleteUser(casdoorsdk.User)`, write user to database.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasdoor%2Fcasdoor-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasdoor%2Fcasdoor-go-sdk/lists"}