Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spectralops/github-scopes-rs
Discover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub.
https://github.com/spectralops/github-scopes-rs
github github-api oauth-app rust
Last synced: about 1 month ago
JSON representation
Discover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub.
- Host: GitHub
- URL: https://github.com/spectralops/github-scopes-rs
- Owner: SpectralOps
- License: apache-2.0
- Created: 2022-05-22T08:40:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-20T18:13:27.000Z (over 2 years ago)
- Last Synced: 2024-10-29T22:47:31.927Z (about 2 months ago)
- Topics: github, github-api, oauth-app, rust
- Language: Rust
- Homepage:
- Size: 24.4 KB
- Stars: 12
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github-scopes-rs
[![Tests](https://github.com/SpectralOps/github-scopes-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/SpectralOps/github-scopes-rs/actions/workflows/ci.yml)
Discover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub.
In many cases, you try to do actions to GitHub, but you get unclear permissions errors. This project allows you to get which permission your token has before, called GitHub, and if you don’t have the right permissions, you can tell the user the exact permission the user needs.## How it works
We called Github api with the given token and get which permissions scope the token has in order the access to the API. Then, the permissions are being converted to a simple object that you can work with.
click [here](https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps) read GitHub documentation.## Usage
Add this to Cargo.toml:
```toml
[dependencies]
github-scopes-rs = { version = "1.0.0" }
```Here's a simple example
```rs
fn main() -> AnyResult<()> {
let permissions = match OAuthContext::new("token") {
Ok(s) => s.get_scope_permissions(),
Err(e) => return Err(e),
};if !permissions.repo.all {
return Err(anyhow!("`repo` permission is mandatory"));
}
Ok(())
}
```You can run it by cloning this repo, and then:
```sh
GITHUB_TOKEN= cargo run --example base
```