{"id":19403171,"url":"https://github.com/4rays/jwt-auth-client","last_synced_at":"2025-02-25T00:25:20.505Z","repository":{"id":256486550,"uuid":"855451404","full_name":"4rays/jwt-auth-client","owner":"4rays","description":"Handle JWT auth and requests in apps using the Swift Composable Architecture (TCA).","archived":false,"fork":false,"pushed_at":"2025-02-04T11:32:51.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-04T12:29:01.049Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/4rays.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-09-10T22:19:48.000Z","updated_at":"2025-02-04T11:32:41.000Z","dependencies_parsed_at":"2024-09-15T21:47:16.276Z","dependency_job_id":"53e526b5-cf07-4074-9c11-711cc6cd262f","html_url":"https://github.com/4rays/jwt-auth-client","commit_stats":null,"previous_names":["4rays/jwt-auth-client"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4rays%2Fjwt-auth-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4rays%2Fjwt-auth-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4rays%2Fjwt-auth-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/4rays%2Fjwt-auth-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/4rays","download_url":"https://codeload.github.com/4rays/jwt-auth-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240578113,"owners_count":19823570,"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":"2024-11-10T11:27:30.601Z","updated_at":"2025-02-25T00:25:20.481Z","avatar_url":"https://github.com/4rays.png","language":"Swift","readme":"# JWTAuth\n\nA dependency client that handles JWT auth in apps using the Swift Composable Architecture (TCA).\n\n## SimpleKeychain\n\nThe library uses the default keychain via the `SimpleKeychain` library.\nIf you want to use a different keychain, you can achieve that via `prepareDependencies`, for instance in the initializer of your `App`.\n\n```swift\ninit() {\n  prepareDependencies {\n    $0.simpleKeychain = SimpleKeychain(...)\n  }\n}\n```\n\n### JWT Auth\n\nA `liveValue` of the `JWTAuthClient` is required.\n\n```swift\nextension JWTAuthClient: DependencyKey {\n  static let liveValue = Self(\n    baseURL: {\n      // Your base URL here\n    },\n    refresh: { token in\n      // Your refresh logic here\n    }\n  )\n}\n```\n\nOnce defined, you can use the following methods:\n\n```swift\npublic func sendAuthenticated\u003cT\u003e(...) async throws -\u003e T where T: Decodable\n\npublic func sendAuthenticated\u003cSuccess, Failure\u003e(...) async throws -\u003e Result\u003cSuccess, Failure\u003e\nwhere Success: Decodable, Failure: Decodable\n```\n\nThe `refreshExpiredToken` parameter is used to determine if the client should retry the request if the token is expired.\nIf set to `false`, the client forwards the server error if the token is expired.\n\n### Auth Tokens Client\n\nThe `AuthTokensClient` is a client that handles the auth tokens via one of the following methods:\n\n```swift\npublic var save: @Sendable (AuthTokens) async throws -\u003e Void\npublic var load: @Sendable () async throws -\u003e AuthTokens?\npublic var destroy: @Sendable () async throws -\u003e Void\n```\n\nYou can access the current cached session using the `@Shared(.sessionTokens)` macro.\n\n\u003e [!NOTE]\n\u003e Unless you call the `refreshExpiredTokens` method on the `JWTAuthClient`,\n\u003e you need to manually call the `load` method of `AuthTokensClient` to load the tokens.\n\n### Keychain Client\n\nThe `KeychainClient` is a client that handles the keychain via one of the following methods:\n\n```swift\npublic var save: @Sendable (_ value: String, _ as: Keys) async throws -\u003e Void\npublic var load: @Sendable (_ key: Keys) async -\u003e String?\npublic var delete: @Sendable (_ key: Keys) async -\u003e Void\npublic var reset: @Sendable () async -\u003e Void\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4rays%2Fjwt-auth-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F4rays%2Fjwt-auth-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F4rays%2Fjwt-auth-client/lists"}