Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update manual github app authentication example #610

Merged
merged 2 commits into from
Mar 22, 2024
Merged
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
11 changes: 7 additions & 4 deletions examples/github_app_authentication_manual.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use octocrab::models::{InstallationRepositories, InstallationToken};
use octocrab::params::apps::CreateInstallationAccessToken;
use octocrab::Octocrab;
use url::Url;

#[tokio::main]
async fn main() -> octocrab::Result<()> {
Expand All @@ -23,11 +24,13 @@ async fn main() -> octocrab::Result<()> {
let mut create_access_token = CreateInstallationAccessToken::default();
create_access_token.repositories = vec!["octocrab".to_string()];

// By design, tokens are not forwarded to urls that contain an authority. This means we need to
// extract the path from the url and use it to make the request.
let access_token_url =
Url::parse(installations[0].access_tokens_url.as_ref().unwrap()).unwrap();

let access: InstallationToken = octocrab
.post(
installations[0].access_tokens_url.as_ref().unwrap(),
Some(&create_access_token),
)
.post(access_token_url.path(), Some(&create_access_token))
.await
.unwrap();

Expand Down
Loading