fix: insert auth headers for api.github.com#754
Merged
Conversation
Contributor
Author
|
@XAMPPRocky |
Owner
|
Thank you for your PR, and congrats on your first contribution! 🎉 |
Merged
|
@pfnsec Should this fix the issue for all API calls? I'm calling let installations = octocrab
.apps()
.installations()
.send()
.await
.unwrap_or(Page::<octocrab::models::Installation>::default())
.take_items();
let id = InstallationId(installation_id);
let Some(installation_index) = installations.iter().position(|l| l.id == id) else {
return Err(Error::FailedToFindAppInstallation(
repository_owner.to_string(),
source_repository.to_string(),
installation_id,
));
};
let installation = &installations[installation_index];
let create_access_token = CreateInstallationAccessToken::default();
// Create an access token for the installation
let access: InstallationToken = octocrab
.post(
installation.access_tokens_url.as_ref().unwrap(),
Some(&create_access_token),
)
.await
.map_err(|_| {
Error::FailedToCreateAccessToken(
repository_owner.to_string(),
source_repository.to_string(),
installation_id,
)
})?;
// Use the API token
let api_with_token = octocrab::OctocrabBuilder::new()
.personal_token(access.token)
.build()
.unwrap();
let app = api_with_token.current().app().await;The last call returns an error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
into_stream()for pagination is currently broken. Consider the following case:When more than 30 files are modified in a pull request, the Github API will return a response with a
linkheader containing a link to the next page of results.Octocrab correctly resolves the
nextURL from this header when it exhausts the first page of results, and so try_next() will make another API call to Github of the formhttps://api.github.com/repositories/{repo_id}/issues?page=2.However, because the authority of this URL is
api.github.comand notNone, Octocrab will not include auth headers with that request, and the request will fail.This pull request alters this behaviour to include auth headers if the URL authority is
Noneor"api.github.com".Fixes:
#576
#738