{"id":29572678,"url":"https://github.com/accelbyte/accelbyte-csharp-sdk","last_synced_at":"2026-04-02T19:32:16.558Z","repository":{"id":59122860,"uuid":"451729016","full_name":"AccelByte/accelbyte-csharp-sdk","owner":"AccelByte","description":"C# Extend SDK generated from AccelByte Gaming Services OpenAPI specification","archived":false,"fork":false,"pushed_at":"2025-07-05T00:00:00.000Z","size":28280,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-09T08:52:55.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","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/AccelByte.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2022-01-25T04:02:28.000Z","updated_at":"2025-07-05T00:00:04.000Z","dependencies_parsed_at":"2024-06-28T01:44:45.690Z","dependency_job_id":"a64a61fa-2cc2-4868-b76b-990f694ee5f8","html_url":"https://github.com/AccelByte/accelbyte-csharp-sdk","commit_stats":{"total_commits":328,"total_committers":11,"mean_commits":"29.818181818181817","dds":"0.18292682926829273","last_synced_commit":"65a9f622792333da8e2020d0a86da6fe88fbc796"},"previous_names":[],"tags_count":81,"template":false,"template_full_name":null,"purl":"pkg:github/AccelByte/accelbyte-csharp-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-csharp-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-csharp-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-csharp-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-csharp-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AccelByte","download_url":"https://codeload.github.com/AccelByte/accelbyte-csharp-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-csharp-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265892511,"owners_count":23845032,"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":[],"created_at":"2025-07-19T05:10:51.197Z","updated_at":"2026-04-02T19:32:16.553Z","avatar_url":"https://github.com/AccelByte.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AccelByte .NET (C#) SDK\n\nA software development kit (SDK) for interacting with AccelByte Gaming Services written in C#.\n\nThis SDK was generated from OpenAPI spec included in the [spec](spec) directory.\n\n## Setup\n\nThis SDK requires .NET 8.0 SDK or at minimum .NET 6.0 to be installed.\n\n## Adding to Your Project\n\n```\ncd /path/to/your_solution/your_project\ndotnet add package AccelByte.Sdk\n```\n\n## Usage\n\n### Environment Variables\n\nThe following environment variables need to be set when using `DefaultConfigRepository`.\n\n| Name               | Required                                         | Example                          |\n|--------------------|--------------------------------------------------|----------------------------------|\n| `AB_BASE_URL`      | Yes                                              | https://test.accelbyte.io        |\n| `AB_CLIENT_ID`     | Yes                                              | abcdef0123456789abcdef0123456789 |\n| `AB_CLIENT_SECRET` | Yes, but only if you use a private `AB_CLIENT_ID`| ab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab |\n| `AB_NAMESPACE`     | Yes                                              | accelbyte                        |\n\n### Instantiation\n    \n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    .UseDefaultConfigRepository() // Using DefaultConfigRepository, make sure the required environment variables are set\n    .UseDefaultTokenRepository()\n    .Build();\n```\n\n## Login\n\n### Login Using Username and Password\n\n```csharp\nbool login = sdk.LoginUser(\"myUsername\", \"myPassword\");\nif (!login)\n{\n    // Login failed  \n}\n```\n\n### Login Using Username and Password with Defined Scopes\n\n```csharp\nbool login = sdk.LoginUser(\"myUsername\", \"myPassword\", \"\u003cselected scopes\u003e\", null);\nif (!login)\n{\n    // Login failed  \n}\n```\n\n### Login Using Username and Password without Scopes\n\n```csharp\nbool login = sdk.LoginUser(\"myUsername\", \"myPassword\", null, null);\nif (!login)\n{\n    // Login failed  \n}\n```\n\n### Login Using OAuth Client\n\n```csharp\nbool login = sdk.LoginClient();\nif (!login)\n{\n    // Login failed  \n}\n```\n\n\u003e :warning: **Please use LoginClient() function with confidential OAuth client:** Using LoginClient() function with public OAuth client is not supported.\n\n\n## Interacting with a Service Endpoint\n\nAs an example, we will get current user profile info using [getMyProfileInfo](https://docs.accelbyte.io/api-explorer/#Basic/getMyProfileInfo) endpoint available in [basic](https://docs.accelbyte.io/api-explorer/#Basic) service.\n\n```csharp\n//Add api namespace\nusing AccelByte.Sdk.Api;\n\n//Add basic service model namespace\nusing AccelByte.Sdk.Api.Basic.Model;\n\n// Login using username and password\n\nbool login = sdk.LoginUser(\"myUsername\", \"myPassword\");\nif (!login)\n{\n    Console.WriteLine(\"Login failed\");\n}\n\n// Instantiate UserProfile wrapper class which is part of basic service\n\nUserProfile userProfile = new UserProfile(sdk);\n\ntry\n{\n    // Make a call to getMyProfileInfo endpoint\n    UserProfilePrivateInfo? response = sdk.Basic.UserProfile.GetMyProfileInfoOp.Execute(sdk.Namespace);\n\n    /*\n    \n    // If you need to modify operation object, first you can build the operation object\n    GetMyProfileInfo operation = sdk.Basic.UserProfile.GetMyProfileInfoOp\n        .Build(sdk.Namespace);\n\n    // then\n    UserProfilePrivateInfo? response = sdk.Basic.UserProfile.GetMyProfileInfo(operation);\n\n    */\n\n    Console.WriteLine(response.UserId); // Success response\n}\ncatch (HttpResponseException e)\n{\n    Console.WriteLine(e.Message);\n}\n```\n\n## Logout\n```csharp\nbool logout = sdk.Logout();\nif (!logout)\n{\n    // Logout failed\n}\n```\n\n## Enable HTTP Logging\nTo enable http logging feature, build the sdk with `EnableLog()`.\n```csharp\nusing AccelByte.Sdk.Core;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    .UseDefaultConfigRepository()\n    .UseDefaultTokenRepository()\n    .EnableLog()\n    .Build();\n```\n\n## HTTP Retry Example\nIf retry feature is required, instantiate the sdk with `ReliableHttpClient` object.\n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\nusing AccelByte.Sdk.Core.Client;\n\n//Using default retry policy \nHttpClientPolicy policy = HttpClientPolicy.Default;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .SetHttpClient(ReliableHttpClient.Builder\n        .SetDefaultPolicy(policy)                    \n        .Build())    \n    .UseDefaultConfigRepository()\n    .UseDefaultTokenRepository()\n    .Build();\n```\n\nFor `HttpClientPolicy` properties, refer to [this code](AccelByte.Sdk/Core/Client//HttpClientPolicy.cs).\n\n## Automatically Refresh Access Token\n\nTo enable automatic access token refresh, include the `AccelByte.Sdk.Feature.AutoRefreshToken` namespace and instantiate the SDK using the following code.\n\n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\n\n//Add feature namespace\nusing AccelByte.Sdk.Feature.AutoRefreshToken;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    // Use DefaultConfigRepository: ensure the required environment variables are set\n    .UseDefaultConfigRepository()    \n    // Call this to enable background token refresh\n    .UseBackgroundTokenRefresh()\n    .Build();\n```\n\nTo configure background token refresh, set following environment variables.\n\n| Name                             | Required | Description                                                                                    |\n|----------------------------------|--------- |------------------------------------------------------------------------------------------------|\n| `AB_REFRESH_RATE`                | No       | Fraction of token lifetime before it is refreshed. Value between`0.0` to `1.0`. Default: `0.8` |\n| `AB_REFRESH_MAX_RETRY`           | No       | Maximum number of retries for refresh token requests before failing. Default: `2`              |\n| `AB_REFRESH_BACKGROUND_INTERVAL` | No       | Timer interval (in seconds) to check token expiry. Default: `10`                               |\n| `AB_REFRESH_BACKGROUND_ENABLED`  | No       | Enables background token refresh. Default: `true`                                              |\n\nNOTE: The `AB_REFRESH_RATE` uses a float value between `0` and `1` representing the fraction of the token's lifetime. For example, if a token is valid for 1 hour (3600 seconds), and `AB_REFRESH_RATE` is set to `0.5`, the SDK will attempt to refresh the token after it has less than 1800 seconds remaining (3600 x 0.5).\n\nBackground token refresh runs on a timer at a specified interval to check for token expiry. If the token is nearing its expiration time (as determined by the `AB_REFRESH_RATE` value), it will be refreshed automatically.\n\nIf a periodic background process is not preferred, use .UseOnDemandTokenRefresh() instead. This method triggers automatic token refresh whenever the SDK calls any AGS endpoint.\nPlease note that this type of token refresh is recommended only for OAuth client logins (using the LoginClient method), as it relies solely on the configured client ID and client secret values. It can be used for other login types, but once the refresh token expires, any subsequent calls will be unauthorized.\n\n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\n\n//Add feature namespace\nusing AccelByte.Sdk.Feature.AutoRefreshToken;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    // Use DefaultConfigRepository: ensure the required environment variables are set\n    .UseDefaultConfigRepository()\n    // call this to enable the feature\n    .UseOnDemandTokenRefresh()\n    .Build();\n```\n\nTo configure on-demand token refresh, set the following environment variables.\n\n| Name                          | Required | Description                                                                                    |\n|-------------------------------|--------- |------------------------------------------------------------------------------------------------|\n| `AB_REFRESH_RATE`             | No       | Fraction of token lifetime before it is refreshed. Value between`0.0` to `1.0`. Default: `0.8` |\n| `AB_REFRESH_MAX_RETRY`        | No       | Maximum number of retries for refresh token requests before failing. Default: `2`              |\n| `AB_REFRESH_ONDEMAND_ENABLED` | No       | Enables token refresh. Default: `true`                                                         |\n\nNOTE: Avoid using both `.UseOnDemandTokenRefresh()` and `.UseBackgroundTokenRefresh()` together, as it introduces unnecessary overhead and may lead to unexpected behavior.\n\nIf any login method is expected to be called multiple times (e.g., in a serverless environment), use `.UseRefreshIfPossible()` when building the SDK:\n```csharp\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    .UseDefaultConfigRepository()\n    .UseDefaultTokenRepository()    \n    .UseDefaultCredentialRepository()\n    // Use this to enable conditional refresh before login\n    .UseRefreshIfPossible()\n    .Build();\n```\n\nThen, use `LoginUser`, `LoginClient`, and/or `LoginPlatform` as usual. With this setup, any call to these methods will first check if the current token is expired:\n- If expired, it will attempt to refresh the token.\n- If still valid, it will return true without re-executing the login process.\n\n## Token Validation\nToken validation is available since version 0.27.\n\nUse following method to validate access token.\n```csharp\nbool isValid = sdk.ValidateToken(accessTokenStr);\n```\n\nPermission validation is available only for OAuth Client token before version 0.47. From version 0.47 onwards, permission validation can accept user token.\nTo validate permission from user token, you need to instantiate the SDK with OAuth Client that has `ADMIN:ROLE [READ]` permission assigned to it.\n\nTo validate permission and action, use following method.\n```csharp\nbool isValid = sdk.ValidateToken(accessTokenStr, permissionStr, actionInt);\n```\n\nTo validate permission and action with specified namespace and/or userid, use following method.\n```csharp\nbool isValid = sdk.ValidateToken(accessTokenStr, permissionStr, actionInt, namespaceId, userId);\n```\n\n## Local Token Validation\nLocal token validation is available since version 0.27.\nTo enable it, include `AccelByte.Sdk.Feature.LocalTokenValidation` and instantiate the sdk with following code.\n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\n\n//Add feature namespace\nusing AccelByte.Sdk.Feature.LocalTokenValidation;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    // Using DefaultConfigRepository, make sure the required environment variables are set\n    .UseDefaultConfigRepository()\n    // Credential repository is required for auto refresh token to works\n    .UseDefaultCredentialRepository()\n    // call this to enable the feature\n    .UseLocalTokenValidator()\n    // call this to enable auto refresh for token revocation list\n    .UseAutoRefreshForTokenRevocationList()\n    // call this to enable auto cache clear for token validator\n    .UseTokenValidatorAutoClearCache()\n    .Build();\n```\nThen use the usual `ValidateToken` methods.\n\nSince version 0.42, `ParseAccessToken` function added to get the access token payload. This function requires 2 parameters. First, is the access token itself. Second, is to set whether the function will validate the access token or not. Set `true` if validation is required.\nTo use it, just include `AccelByte.Sdk.Feature.LocalTokenValidation`. If validation is required, instantiate the sdk with following code.\n```csharp\n//Add core namespace\nusing AccelByte.Sdk.Core;\n\n//Add feature namespace\nusing AccelByte.Sdk.Feature.LocalTokenValidation;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    // Using DefaultConfigRepository, make sure the required environment variables are set\n    .UseDefaultConfigRepository()\n    // Credential repository is required for auto refresh token to works\n    .UseDefaultCredentialRepository()\n    // call this to enable the feature\n    .UseLocalTokenValidator()\n    // call this to enable auto refresh for token revocation list\n    .UseAutoRefreshForTokenRevocationList()\n    // call this to enable auto cache clear for token validator\n    .UseTokenValidatorAutoClearCache()\n    .Build();\n```\n\nAnd to use it.\n```csharp\nvar payload = sdk.ParseAccessToken('\u003caccess token\u003e', false);\n\n//or, if validation is required\nvar payload = sdk.ParseAccessToken('\u003caccess token\u003e', true);\n```\n`ParseAccessToken` will return null if the access token is invalid.\n\nSince version 0.54, both permission and namespace context cache can be cleared manually or automatically with set interval.\n- To use it manually, call `sdk.Configuration.TokenValidator.InvalidateCache()`.\n- to enable auto clear, instantiate the sdk with `UseTokenValidatorAutoClearCache(\u003cinterval in seconds\u003e)` method.\n\n## Operation with Generic Response\nSince 0.28, C# Extend SDK enable overloaded `ParseOperation` method with generic data type that applies to almost all operations with response model which has one or more object data type in it.\nFor example:\n```csharp\nusing AccelByte.Sdk.Api.Cloudsave.Model;\nusing AccelByte.Sdk.Api.Cloudsave.Operation;\n\nGameRecordExample myGameRecord = new GameRecordExample()\n{\n    MyStatus = \"ALIVE\",\n    Location = \"MOUNTAIN\",\n    Character = new GameRecordExample.CharacterClass()\n    {\n        Name = \"Character\",\n        Strength = 10,\n        Agility = 15,\n        Intelligence = 20\n    }\n};\n\nModelsGameRecordResponse\u003cGameRecordExample\u003e? response = sdk.Cloudsave.PublicGameRecord.PostGameRecordHandlerV1Op\n    .Execute\u003cGameRecordExample\u003e(myGameRecord, \"test_record\", sdk.Namespace);\n```\nThe list of which endpoints that support it can be found in [here](docs/operations/)\n\n## FlightID\nSince 0.53, C# Extend SDK enable support for FlightID transmission during Http request. By default, new flight id will be generated when the sdk is loaded. There will be some case that this default value need to be updated with new value.\n-   To update default flight id globally, use following code:\n    ```csharp\n    AccelByteConfig.UpdateDefaultFlightId(\"\u003cnew flight id value\u003e\");\n    ```\n    This will update the default flight id, and will be used by newly created sdk object (won't affect existing sdk object created before this code get executed).\n\n-   To update flight id value in sdk object, use following code:\n    ```csharp\n    sdk.UpdateFlightId(\"\u003cnew flight id value\u003e\");\n    ```\n    This will update the flight id value stored inside the sdk object. Will be used for all operations executed by the sdk object.\n\n-   To update flight id value for specific operation, use `UpdateFlightId` method when building the operation object.\n    ```csharp\n    // Make a call to getMyProfileInfo endpoint\n    UserProfilePrivateInfo? response = sdk.Basic.UserProfile.GetMyProfileInfoOp\n        .UpdateFlightId(\"\u003cnew flight id value\u003e\")\n        .Execute(sdk.Namespace);\n    ```\n\n## Web Socket Service\n\nC# Extend SDK is able to connect to Lobby Web Socket Service. Following code demonstrate on how to use it.\n```csharp\n\nusing AccelByte.Sdk.Core;\n\nAccelByteSDK sdk = AccelByteSDK.Builder\n    .UseDefaultHttpClient()\n    .UseDefaultConfigRepository()\n    .Build();\n\n// do login first\n\nvar lobbyWs = new LobbyService(sdk.Configuration);\n\n//start connect\nawait lobbyWs.Connect(false);\n\n//listen to message, this will block the execution\nawait lobbyWs.Listen();\n\n//disconnect\nawait lobbyWs.Disconnect();\n```\n\nBy default, web socket service is allowed to reconnect when not normal closure is received. To disable it, set `AllowReconnect` to false.\n```csharp\nlobbyWs.AllowReconnect = false;\n```\n\nTo handle message, register the event on which message type. For example:\n```csharp\nlobbyWs.OnFriendsStatusResponse = (data) =\u003e\n{\n\n};\n```\n\nIn some cases, it is probably desired to handle all incoming message in single handler. To do this, set `RedirectAllReceivedMessagesToMessageReceivedEvent` to true and register an action to `OnMessageReceived`.\n```csharp\nlobbyWs.RedirectAllReceivedMessagesToMessageReceivedEvent = true;\nlobbyWs.OnMessageReceived = (message) =\u003e\n{\n    \n};\n```\n\n## Samples\n\nSee common use cases [here](docs/common_use_cases.md).\n\nSample apps are available in the [samples](samples) directory.\n\n## Migration Guides\nSee [here](docs/migration-guides) for migration guides.\n\n## Documentation\nReference about AccelByte Gaming Services endpoints and their corresponding SDK API is available in [docs/operations](docs/operations) directory.\n\nSample app documentations are available in the [docs/samples](docs/samples/) directory.\n\nFor documentation about AccelByte Gaming Services and SDK, see [docs.accelbyte.io](https://docs.accelbyte.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-csharp-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccelbyte%2Faccelbyte-csharp-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-csharp-sdk/lists"}