GitHub - URL could not be accessed: HTTP/1.1 400 Bad Request - github

I am using a private repository in my project ( for example https://github.com/org/repo), and recently I am getting the below error message when I trying to run composer install.
[Composer\Downloader\TransportException]
The 'https://api.github.com/repos/org/myrepo' URL could not be accessed: HTTP/1.1 400 Bad Request

You have to update your auth.json file. Please go to Settings > Developer settings > Personal access tokens (Direct URL: https://github.com/settings/tokens) page and generate a new token and copy the token string then enable sso and authorise with your private organisation. Update your auth.json like below format.
{
"http-basic": {
"github.com": {
"username": "<YOUR-USERNAME>",
"password": "<NEW_TOKEN>"
}
}
}

Related

How to Properly Set Permissions for a Custom Strapi Plugin

Strapi Version: 4.1.5
Operating System: Debian GNU/Linux 9
Database: PostgreSQL 13
Node Version: v14.16.0
NPM Version: 6.14.11
Yarn Version: v1.22.5
Hi everyone, I can’t seem to find consistent information on how to use permissions with a custom plugin in Strapi. I want to make an endpoint available to my front-end (Next.JS) application, but only when the front-end application has authenticated as a user and using the JWT that is returned from authenticating with Strapi. I keep getting a 401 returned.
Here’s what I’m doing:
I used this page to set up authentication in Strapi. I have a user created in Strapi, and from the front-end, I can authenticate and it returns a JWT token. When I set up collection types to only be accessible with the “authenticated” role, I can access those collection types in the api using this JWT token. So all of that works. The problem is that I can’t get this to work with my custom plugin, and I’m not sure why. I still get a 401 error instead.
Here’s how I set up the permissions:
Based on this page, I initially tried to leverage the isAuthenticated permission that the Users & Permissions plugin provides:
{
method: "GET",
path: "/progress",
handler: "memberProgress.getProgress",
config: {
policies: ['plugins::users-permissions.isAuthenticated']
},
},
Unfortunately, this did not work. The server raised an error, saying that this could not be found. So back on the document linked above, I decided to take the approach of creating my own gloabl permission. I created src/policies/is-authenticated.js with the following contents:
module.exports = (policyContext, config, { strapi }) => {
if (policyContext.state.user) { // if a session is open
// go to next policy or reach the controller's action
return true;
}
return false; // If you return nothing, Strapi considers you didn't want to block the request and will let it pass
};
Then, I modified my plugin’s route as follows:
{
method: "GET",
path: "/progress",
handler: "memberProgress.getProgress",
config: {
policies: ['global::is-authenticated']
},
},
This is all based on that document I linked to. Unfortunately, this still does not work. It seems to find the permission (server doesn’t raise an error about it), but when I try to access my plugin’s endpoint with the JWT token, I just get a 401 error.
Here is how I’m trying to access the endpoint on the front-end:
// VERIFIED, auth works and I get the expected jwt
const strapiAuth = await strapiApiAuth();
if ( strapiAuth && strapiAuth.hasOwnProperty("jwt") ) {
try {
const response = await axios.get(
`${process.env.STRAPI_BACKEND_URL}/member-progress/progress?year=2022&name=&pageSize=10&page=1`,
{
headers: {
Accept: "application/json",
Authorization: `Bearer ${strapiAuth.jwt}`
},
timeout: 500,
}
);
console.log(response);
} catch (error) {
// This is where I land with the 401 error
console.log(error);
}
}
Strapi check if you have a valid jwt by default with "authenticated" role, but you must mark the permission to your custom endpoint in "Settings→User & Permission Plugin→Roles" of admin panel also.

Github api returns bad credentials even with oauth token

update: even such a request get bad credential ==>
curl -H "Authorization: token [token]" https://api.github.com
===============
I made a request for GitHub OAuth like this in my iOS app:
URL: https://github.com/login/oauth/authorize,
params: client_id: ****, redirect_uri: app_url, scope: "repo", state: "0"
After redirection from Safari I get a code. I need to access to two things:
User data, like email and etc. Also updating user data.
List of repositories and commits in public and private repos.
I make following requests:
URL: https://api.github.com/user, get and patch
Header: Authorization: token [code]
URL: https://api.github.com/repos/:username/:repoName
Header: Authorization: token [code]
But unfortunately, I get the following error:
401, Unauthorized
{
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
What is the problem and how can I solve it?
As it is said in this blob (NOT the main documentation) you have to exchange token (which is temporary) with a bearer token via this api:
the main api
Here comes the documentation for others:
Github blob documentation
The following curl command works:
curl -u your_git_name:your_personal_access_token https://api.github.com/user

How to do a source import with GitHub APIv3

background:
I am trying to build an application that will copy a public repository to the logged in account.
Now i am trying to do a source import in PostMan and i am using the following settings:
i make a PUT request to this link:
https://api.github.com/repos/{myusername}/{empty github repository}/import
with the following header:
Accept:application/vnd.github.barred-rock-preview
With this body:
{
"vcs": "git",
"vcs_url": "https://github.com/{owner of repo i want to copy}/{repo i want to copy}",
"vcs_username": "{myusername}",
"vcs_password": "{mypassword}"
}
I have read the github API for importing repositories. But i am getting the following response from the server:
{
"message": "Not Found",
"documentation_url":
"https://developer.github.com/v3/migrations/source_imports/#start-an-import"
}
Why does the server return a Not Found? How do i get this to work
It need Authentication else will get 404 Not Found
using username and password for authentication
Put URL:
https://{myusername}:{mypassword}#api.github.com/repos/{myusername}/{myreponame}/import
Request Body
{
"vcs": "git",
"vcs_url": "https://github.com/{ownerRepo}/{ownerRepoName}"
}
vcs_username and vcs_password used for remote repo not yours.

HTTP 401 error message when I try with private enterprise Github account

I am working with python + the requests library + github access to get a hook URL.
When I try to access a hook from my personal public git repo, I get the response smoothly:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://api.github.com/repos/josenrihernand/github-personal-repo/hooks", auth=("josenrihernand", token)).json()
print("RESPONSE: ", response) ---> IT WORKS (I get the hook url)
However, if I try with a enterprise / private github account, I get an HTTP 401 error message:
import json
import requests
token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
response = requests.get("https://MY_DOMAIN/repos/ENTERPRISE_USER/REPO_PATH/hooks", auth=("ENTERPRISE_USER", token)).json()
print("RESPONSE: ", response) ---> I got a 401 error message.
I am sure that the token is ok.
What could be the root cause of that error ?
Is the get address properly formed ?
thanks a lot!
Github entreprise base URL for v3 API is :
http(s)://hostname/api/v3/
check Rest v3 API doc
I guess in your case it would be :
https://your.domain/api/v3/repos/USER/REPO/hooks

How Do I Change The Project Owner Using REST API

I want to change the project owner of a project using REST API. I know there is a "/Owner" endpoint and I can get the owner without any problems with the following GET:
site/_api/ProjectServer/Projects('2cc734f2-cd16-4f09-8632-a2bc74a32577')/Owner
So how do I change the project owner using REST API?
This is an old issue but I figured it might help someone since I recently struggeled with this too.
I have only tested this on Project Online and not on-prem, probably works the same on Project Server 2016
Start by checking out the project
Send a PATCH request to:
_api/ProjectServer/Projects('PROJECT ID')/Draft
with the following headers:
Accept: application/json; odata=verbose
Content-Type: application/json; odata=verbose
X-RequestDigest: The request digest
If-Match: Either "*" or the etag value you get from checking out the project
and the request body:
{
"__metadata": {
"type": "PS.DraftProject"
},
"OwnerId": "SharePoint User ID of the owner"
}
It's important that you send the "OwnerId" value as a string, not a number.
Publish the project
The general way to change site owners using REST API according to MSDN is:
POST http://<sitecollection>/<site>/_api/site/owner
So in your case you should just have to change from a GET command to POST