{"id":22048543,"url":"https://github.com/samhammerag/oauth2authenticator","last_synced_at":"2025-05-08T23:02:25.885Z","repository":{"id":39968804,"uuid":"494022373","full_name":"SamhammerAG/OAuth2Authenticator","owner":"SamhammerAG","description":"OAuth2 client for retrieving OAuth2 tokens and common token handling logic such as refresh and client credentials.","archived":false,"fork":false,"pushed_at":"2025-04-14T14:29:47.000Z","size":104,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-14T15:47:03.330Z","etag":null,"topics":["authentication","authenticator","csharp","dotnet","dotnet-core","nullable-reference-types","oauth","oauth2","oauth2-authentication","oauth2-client","token-authetication","token-management"],"latest_commit_sha":null,"homepage":"","language":"C#","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/SamhammerAG.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,"zenodo":null}},"created_at":"2022-05-19T10:22:34.000Z","updated_at":"2025-04-14T14:29:50.000Z","dependencies_parsed_at":"2023-12-06T15:28:00.212Z","dependency_job_id":"3dc578de-6051-4f35-a4aa-21d526b65be1","html_url":"https://github.com/SamhammerAG/OAuth2Authenticator","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamhammerAG%2FOAuth2Authenticator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamhammerAG%2FOAuth2Authenticator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamhammerAG%2FOAuth2Authenticator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamhammerAG%2FOAuth2Authenticator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamhammerAG","download_url":"https://codeload.github.com/SamhammerAG/OAuth2Authenticator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160770,"owners_count":21863627,"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","authenticator","csharp","dotnet","dotnet-core","nullable-reference-types","oauth","oauth2","oauth2-authentication","oauth2-client","token-authetication","token-management"],"created_at":"2024-11-30T14:12:44.281Z","updated_at":"2025-05-08T23:02:25.856Z","avatar_url":"https://github.com/SamhammerAG.png","language":"C#","readme":"# OAuth2Authenticator\n[![ci](https://github.com/SamhammerAG/OAuth2Authenticator/workflows/CI/badge.svg)](https://github.com/SamhammerAG/OAuth2Authenticator)\n\nOAuth2 client for retrieving OAuth2 tokens and common token handling logic such as refresh and client credentials.\n\n[Nuget Package](https://www.nuget.org/packages/OAuth2Authenticator)\n\n## Currently supported grant types\n* [Password](https://oauth.net/2/grant-types/password/)\n* [Refresh Token](https://oauth.net/2/grant-types/refresh-token/)\n* [Client Credentials](https://oauth.net/2/grant-types/client-credentials/)\n\n## Setup\nInitialize the client service in the application startup. \n```cs\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.InitOAuth2Authenticator();\n}\n```\n\n## Usage\n### OAuth2Authenticator\nThis class holds the request logic for all OAuth2 grant types. Injectable over the `IOAuth2Authenticator` interface.\n```cs\nprivate readonly IOAuth2Authenticator _authenticator;\n\nawait _authenticator.PasswordGrant(url, clientId, username, password);\n\nawait _authenticator.RefreshTokenGrant(url, clientId, refreshToken);\n\nawait _authenticator.ClientCredentialsGrant(url, clientId, clientSecret);\n```\nAfter the request, a `OAuth2TokenResponse` or `null` returns.\n\n\n### OAuth2TokenHandler\nThis class holds common logic which is needed for token handling. Injectable over the `IOAuth2TokenHandler` interface.\n\n#### RefreshHandler\nThe refresh handler checks whether the access token is about to expire or has already expired and automatically attempts to renew the token with the refresh token. If a renewal with the refresh token is not possible, a new token is retrieved via the specified callback. The handler always attempts to return a valid token.\n```cs\nprivate readonly IOAuth2TokenHandler _handler;\nprivate static OAuth2TokenResponse token; // Save the last token somewhere static or distributed.\n\ntoken = await _handler.RefreshHandler(\n    token,\n    url,\n    clientId,\n    async () =\u003e\n    {\n        // Is executed to obtain a new token if an refresh was not possible or none exists yet.\n        return await _authenticator.PasswordGrant(url, clientId, username, password);\n    });\n```\n\n#### ClientCredentialsHandler\nThe client credentials handler checks whether the access token is about to expire or has already expired and automatically requests a new token.\n```cs\nprivate readonly IOAuth2TokenHandler _handler;\nprivate static OAuth2TokenResponse token; // Save the last token somewhere static or distributed.\n\ntoken = await _handler.ClientCredentialsHandler(\n    token,\n    url,\n    clientId,\n    clientSecret);\n```\n\n### OAuth2TokenResponseExtension\nChecks if the token request was successful.\n```cs\ntoken.Successful()\n```\n\nChecks that the token is not expired.\n```cs\ntoken.Valid()\n```\n\n\n## API Reference\n* [OAuth2Authenticator](https://www.fuget.org/packages/OAuth2Authenticator)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhammerag%2Foauth2authenticator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamhammerag%2Foauth2authenticator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamhammerag%2Foauth2authenticator/lists"}