Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 83 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ serde_json = "1"
serde_urlencoded = "^0.7"
url = { version = "2", features = ["serde"] }
tokio = { version = "1.8.0", features = ["full"] }
github-scopes-rs = { version = "1" }

[dev-dependencies]
base64 = "^0.12"
Expand Down
18 changes: 18 additions & 0 deletions github/examples/get_token_scopes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::env;

use anyhow::{anyhow, Result};
use octorust::scopes;

fn main() -> Result<()> {
let token = match env::var("GITHUB_TOKEN") {
Ok(t) => t,
Err(_e) => return Err(anyhow!("github token not provide")),
};

let permissions = scopes::OAuth::from_token(token.as_str())?;

if !permissions.repo.all {
return Err(anyhow!("`repo` permission is mandatory"));
}
Ok(())
}
2 changes: 2 additions & 0 deletions github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ pub mod reactions;
pub mod repos;
/// Provisioning of GitHub organization membership for SCIM-enabled providers.
pub mod scim;
/// Provides exactly what type of access you have by a given token.
pub mod scopes;
/// Look for stuff on GitHub.
pub mod search;
/// Retrieve secret scanning alerts from a repository.
Expand Down
20 changes: 20 additions & 0 deletions github/src/scopes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Result;
use github_scopes_rs::{oauth::OAuthContext, transform::GithubTokenScope};

pub struct OAuth {}

impl OAuth {
/**
* Scopes returns exactly what type of access you have by a given token.
*
* This function discover the exactly oauth scope permissions of the given token.
*
* **Note:** Accessing this endpoint does not count against your REST API rate limit.
*
* FROM: <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps>
*/
pub fn from_token(token: &str) -> Result<GithubTokenScope> {
let p = OAuthContext::new(token)?;
Ok(p.get_scope_permissions())
}
}