{"id":22385494,"url":"https://github.com/sersoft-gmbh/auth-scope","last_synced_at":"2025-07-31T04:33:21.913Z","repository":{"id":37693487,"uuid":"199058440","full_name":"sersoft-gmbh/auth-scope","owner":"sersoft-gmbh","description":"A swift library to deal with authentication scopes","archived":false,"fork":false,"pushed_at":"2024-09-18T14:29:16.000Z","size":2159,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-17T17:35:51.048Z","etag":null,"topics":["auth","oauth","scope","swift"],"latest_commit_sha":null,"homepage":"https://sersoft-gmbh.github.io/auth-scope/","language":"Swift","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/sersoft-gmbh.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-26T17:49:40.000Z","updated_at":"2024-09-18T13:16:25.000Z","dependencies_parsed_at":"2024-04-08T07:51:09.275Z","dependency_job_id":null,"html_url":"https://github.com/sersoft-gmbh/auth-scope","commit_stats":{"total_commits":163,"total_committers":2,"mean_commits":81.5,"dds":"0.48466257668711654","last_synced_commit":"3e29ccc3bc12035da0a20a73e7f3d9fd26943bf8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sersoft-gmbh%2Fauth-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sersoft-gmbh%2Fauth-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sersoft-gmbh%2Fauth-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sersoft-gmbh%2Fauth-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sersoft-gmbh","download_url":"https://codeload.github.com/sersoft-gmbh/auth-scope/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228217216,"owners_count":17886703,"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","oauth","scope","swift"],"created_at":"2024-12-05T01:25:58.074Z","updated_at":"2024-12-05T01:25:58.758Z","avatar_url":"https://github.com/sersoft-gmbh.png","language":"Swift","readme":"# AuthScope\n\n[![GitHub release](https://img.shields.io/github/release/sersoft-gmbh/auth-scope.svg?style=flat)](https://github.com/sersoft-gmbh/auth-scope/releases/latest)\n![Tests](https://github.com/sersoft-gmbh/auth-scope/workflows/Tests/badge.svg)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/fc57ce86aee7414393d268ef658adb21)](https://www.codacy.com/gh/sersoft-gmbh/auth-scope/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=sersoft-gmbh/auth-scope\u0026amp;utm_campaign=Badge_Grade)\n[![codecov](https://codecov.io/gh/sersoft-gmbh/auth-scope/branch/master/graph/badge.svg)](https://codecov.io/gh/sersoft-gmbh/auth-scope)\n[![Docs](https://img.shields.io/badge/-documentation-informational)](https://sersoft-gmbh.github.io/auth-scope)\n\nHandle authentication scopes with ease.\n\n## Installation\n\n### Swift Package Manager\n\nAdd the following package dependency to your `Package.swift`:\n```swift\n.package(url: \"https://github.com/sersoft-gmbh/auth-scope\", from: \"4.0.0\"),\n```\n\n## Usage\n\nThe main object you want to use is `Scope\u003cAccessRange\u003e`. It's generic and wraps all the logic around a given `AccessRange` type. Since `Scope` can't know what access ranges you have, you need to provide them yourself. Typically, this is done by using an `enum` and conforming it to `AccessRangeProtocol`:\n```swift\nenum MyAccessRange: String, AccessRangeProtocol, CaseIterable {\n    case readPosts = \"posts:read\"\n    case writePosts = \"posts:write\"\n\n    case readUsers = \"users:read\"\n    case writeUsers = \"users:write\"\n}\n```\n\nYou can then use your `enum` with `Scope`:\n```swift\nlet postsScope = Scope\u003cMyAccessRange\u003e(accessRanges: .readPosts, .writePosts)\n\npostsScope.contains(.writePosts) // -\u003e true\npostsScope.contains(.readUsers) // -\u003e false\n```\n\n`Scope` conforms to `SetAlgebra` to make checking access ranges easier:\n```swift\nlet completeScope = Scope\u003cMyAccessRange\u003e.all // `.all` is available when `AccessRange` conforms to `CaseIterable`\ncompleteScope.isSuperset(of: postsScope) // -\u003e true\n```\n\n`Scope` is also able to generate a \"scope string\", since this is usually how they're provided to APIs. The \"scope string\" contains all access ranges (their `rawValue` to be exact) separated by space. It's important to note that `Scope` does not keep the access ranges in a given order. This means, that it's not guaranteed that two calls to `scopeString` will contain the access ranges in the same order. It is guaranteed, however, that the resulting scope contains all access ranges. `Scope` can of course also be created from a scope string. This initializer will throw an error if any of the contained access ranges is not valid.\n\n```swift\nlet usersScope: Scope\u003cMyAccessRange\u003e = [.readUsers, .writeUsers]\nlet string = usersScope.scopeString // -\u003e \"users:read users:write\" OR \"users:write users:read\"\nlet recreatedScope = try Scope\u003cMyAccessRange\u003e(scopeString: string)\nusersScope == recreatedScope // true\n```\n\n`Scope` is also `Codable` and encodes/decodes itself as its scope string.\n\nLast but not least, `Scope` also provides some useful regular expression patterns, that can be used to perform matches on a string basis. This is not recommended if your scopes are available as Swift types, but can be useful if you have to match scopes e.g. in a database.\nThere are currently three regular expression patterns that are provided:\n-   `exactMatchRegexPattern`: Returns a pattern that matches a scope string that contains **exactly** the same access ranges. Not more and not less.\n-   `containsAllRegexPattern`: Returns a pattern that matches a scope string that contains **all** access ranges, but is allowed to contain more.\n-   `containsAnyRegexPattern`: Returns a pattern that matches a scope string that contains **any** access ranges. A match is made as soon as one access range is contained.\n\nFor all these patterns, a `Regex` is available as well.\n\n## Documentation\n\nThe API is documented using header doc. If you prefer to view the documentation as a webpage, there is an [online version](https://sersoft-gmbh.github.io/auth-scope) available for you.\n\n## Contributing\n\nIf you find a bug / like to see a new feature in AuthScope there are a few ways of helping out:\n\n-   If you can fix the bug / implement the feature yourself please do and open a PR.\n-   If you know how to code (which you probably do), please add a (failing) test and open a PR. We'll try to get your test green ASAP.\n-   If you can do neither, then open an issue. While this might be the easiest way, it will likely take the longest for the bug to be fixed / feature to be implemented.\n\n## License\n\nSee [LICENSE](./LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsersoft-gmbh%2Fauth-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsersoft-gmbh%2Fauth-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsersoft-gmbh%2Fauth-scope/lists"}