github-scopes-rs

Crates.iogithub-scopes-rs
lib.rsgithub-scopes-rs
version1.0.1
sourcesrc
created_at2022-05-24 11:10:01.275194
updated_at2022-09-20 18:16:14.035931
descriptionDiscover GitHub token scope permission and return you an easy interface for checking token permission before querying GitHub
homepagehttps://github.com/SpectralOps/github-scopes-rs
repositoryhttps://github.com/SpectralOps/github-scopes-rs
max_upload_size
id592718
size64,831
Elad Kaplan (kaplanelad)

documentation

https://docs.rs/github-scopes-rs

README

github-scopes-rs

Tests

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 read GitHub documentation.

Usage

Add this to Cargo.toml:

[dependencies]
github-scopes-rs = { version = "1.0.0" }

Here's a simple example

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:

GITHUB_TOKEN=<TOKEN> cargo run --example base
Commit count: 7

cargo fmt