Curl - implicit grant - linux

Any chance that I can get this OAUTH system to let me login with curl?
When I make the following call with curl, I keep getting the error message bellow and can't get passed it.
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&response_type=code&client_id=xxx_id_xxx&client_secret=xxx_secret_xxx&redirect_uri=https://www.anaf.ro" "https://logincert.anaf.ro/anaf-oauth2/v1/authorize"
{
"error":"invalid_client",
"error_description":"The client app does not support implicit grant"
}
Thanks,
Chris

Related

Get à 401 Unauthorized when trying to lint my gitlab-ci.yml (version 13.8)

Since monday, I'm not able to use the lint CI API from gitlab, which is documented here https://docs.gitlab.com/ee/api/lint.html#validate-the-ci-yaml-configuration
I'm working on a self hosted gitlab, and we updated gitlab to the last version (13.8.4).
I've noticed that the documentation has changed between 13.8 and 13.9, they mentioned
Access to this endpoint requires authentication.
So I tried to generate a personal access token with full access (I'm admin), but I still get a 401.
Here is my try :
$ curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: P3r50Na1t0k3N" "https://my-domain.artips.fr/api/v4/ci/lint" --data '{"content": "{ \"image\": \"ruby:2.6\", \"services\": [\"postgres\"], \"before_script\": [\"bundle install\", \"bundle exec rake db:create\"], \"variables\": {\"DB_NAME\": \"postgres\"}, \"types\": [\"test\", \"deploy\", \"notify\"], \"rspec\": { \"script\": \"rake spec\", \"tags\": [\"ruby\", \"postgres\"], \"only\": [\"branches\"]}}"}'
# Result : {"message":"401 Unauthorized"}
# Other try
$ curl -X POST --header "Content-Type: application/json" --header "PRIVATE-TOKEN: P3r50Na1t0k3N" "https:///my-domain.artips.fr/api/v4/ci/lint" --data '{"content": "{ \"image\": \"ruby:2.6\", \"services\": [\"postgres\"], \"before_script\": [\"bundle install\", \"bundle exec rake db:create\"], \"variables\": {\"DB_NAME\": \"postgres\"}, \"types\": [\"test\", \"deploy\", \"notify\"], \"rspec\": { \"script\": \"rake spec\", \"tags\": [\"ruby\", \"postgres\"], \"only\": [\"branches\"]}}"}'
# same result: {"message":"401 Unauthorized"}
Has anyone run into the same problem ?
Thanks in advance
Takeshi
There is an ongoing issue regarding the CI Lint API endpoint. It seems that authentication for this endpoint doesn't work when "signing up" is disabled on on-premise Gitlab instance. I guess the issue will be fixed in future releases.
The user token's scope must grant read/write permission to yout gitlab instance's API (as you may see in the picture). The user hasn't to be admin.
import requests
import urllib.parse
from requests.auth import HTTPBasicAuth
url = 'https://gitlab.example.com/'
api = urllib.parse.urljoin(url, '/api/v4/projects')
private_token = 'xxx'
params = dict(private_token=private_token)
auth = HTTPBasicAuth('username', 'password') # username and password, different from login account, generally provided from ops
response = requests.get(api, params, auth=auth)
print(response)
print(response.json())

How can I use the GitHub Rest API to update a repository that is part of an organization?

I have a large number of GitHub repositories that have been sorted into various organizations. I wish to change the visibility of the repos by batch to public using the following API call:
curl -u {user}:{pat} -H "Accept: application/vnd.github.v3+json" -X PATCH https://api.github.com/repos/{user}/angular.powershifter -d '{"private":false}'
Which as best as I can tell is the API call (see github docs). The {user] and {pat} in the sample above are real values, and the {pat} has every option selected. The {user} is both the owner of the repo and the organization.
What I get in response is is a 404 with the following body.
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/reference/repos#update-a-repository"
}
Is it possible to set the properties of repositories under an organization using the API?
What is the API call?
Bonus points if you can point me to the documentation!
Thanks.
Use Bearer Token based authentication. Github is deprecating password based authentications.
curl \
-H 'Authorization: Bearer ${GITHUB-TOKEN}' \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${OWNER}/${repo} \
-d '{"private":"false"}'
Link for the github documentation
https://docs.github.com/en/free-pro-team#latest/rest/overview/other-authentication-methods
Yes it is possible.
I've had some issues with this too.
Short answer use bearer token (As #shek said), and change false to "false":
curl -v -H "Authorization: Bearer ${GITHUB_TOKEN}"
-X PATCH https://api.github.com/repos/${ORGANIZATION}/${REPO}
-H "Accept: application/vnd.github.v3+json" -d '{"private": "false"}';
Notice that your token has full control of private repositories when creating the token:
full control of private repositories image
The link is quite confusing, because if for example you need to get all the repositories from GitHub you'll have to use:
https://api.github.com/orgs/${ORGANIZATION}/repos?${parameters}
Also when you need to change permissions you'll need to use:
https://api.github.com/orgs/${ORGANIZATION}/teams/${TEAM}/repos/${ORGANIZATION}/${REPO}
(Notice the orgs, which is missing in the PATCH command).
GitHub repositories documentation:
https://docs.github.com/en/rest/reference/repos#update-a-repository
GitHub auth methods (From #shek):
https://docs.github.com/en/free-pro-team#latest/rest/overview/other-authentication-methods

How to test QnA knowledge base with fiddler

I just created a qna knowledge base but i'm finding it difficult to consume the endpoint api. I have actually done this before Microsoft changed the endpoint configuration features. please find below my test credentials
POST /knowledgebases/6a523867-3606-480e-9179-bd7e06df4b4d/generateAnswer
Host: https://kb12.azurewebsites.net/qnamaker
Authorization: EndpointKey 604c416d-ef24-402d-b889-cbbb4c16a396
Content-Type: application/json
{"question":"hi"}
i used `Ocp-Apim-Subscription-Key: 604c416d-ef24-402d-b889-cbbb4c16a396 but i keep getting 502 error
.
keep getting 502 error
I do a test using fiddler and can reproduce same issue, to solve the issue, you can go Tools > Options > HTTPS to make tls1.2 allowable.
Test result:
Curl example that works for me -
replace xxxx..., yyyy...., and myazureresourcename with your own values shown on the publish page.
curl \
--header "Content-type: application/json" \
--header "Authorization: EndpointKey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
--request POST \
--data '{"question":"what is my endpoint?"}' \
https://myazureresourcename.azurewebsites.net/qnamaker/knowledgebases/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy/generateAnswer

upload .pcm file using okhttp

I am trying to convert speech to text using Nuance so i am trying to send this request
curl "https://dictation.nuancemobility.net:443/NMDPAsrCmdServlet/dictation?appId=[INSERT YOUR APP ID]&appKey=[INSERT YOUR 128-BYTE STRING APP KEY]&id=C4461956B60B" -H "Content-Type: audio/x-wav;codec=pcm;bit=16;rate=16000" -H "Accept-Language: ENUS" -H "Transfer-Encoding: chunked" -H "Accept: application/xml" -H "Accept-Topic: Dictation" -k --data-binary #audio_16k16bit.pcm
need to upload audio file (.pcm) format.
I am using okhttp3 library following is the builder
RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file", "audio_16k16bit.pcm", RequestBody.create(MEDIA_TYPE_PNG, "audio_16k16bit"))
.build();
httpBuider.addQueryParameter("appId", "NMDPTRIAL_XXXXXXX_XXX_com20161122071457").addQueryParameter("appKey", "fadaed7b801e10d84272c0a75317d8cee13ab86ae902ab322cd6e1219fcbe79aa5d41526f225fe3497bfdbead6b4b9b7ee7122d773cd0a9fa3ebc042b7a7dc5c");
Request request = new Request.Builder().addHeader("Content-Type","audio/x-wav;codec=pcm;bit=16;rate=16000").addHeader("Accept-Language","eng-GBR").addHeader("Transfer-Encoding","chunked").addHeader("Accept","application/xml").addHeader("Accept-Topic","Dictation").post(requestBody).url(httpBuider.build()).build();
I am getting following log
HTTP ERROR 500
Problem accessing /NMDPAsrCmdServlet/dictation. Reason:
Server Error
Missing anything?
I have experienced the same just now using Jersey. Problem for me was, that Jersey was overwriting the content type header (I tried with Application_Octet_Stream).
Here is the request with which I finally got it to work:
Response myResponse = target.
request().
accept(MediaType.TEXT_PLAIN_TYPE).
header("Accept-Language","DEDE").
header("Accept-Topic", "Dictation").
header("Transfer-Encoding","chunked").
post(Entity.entity(speechStream, "audio/x-wav;codec=pcm;bit=16;rate=16000"));
I suggest using something like fiddler to find out what is really posted and comparing that to the curl post. This is how I finally found out what was wrong with my request.
Remove the header "Transfer-Encoding","chunked". My error was fixed by removing it.

Github API Create Issues return 404 Not found

I am making a request to the below URL-
Post https://api.github.com/repos/kvimal/2048/issues
With my Token as a header for authorization.
The Curl Request
curl -i -X POST https://api.github.com/repos/kvimal/2048/issues -d "{title:'hey'}" -H "Authorization: Bearer xxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json"
And GitHub sends a response 404 Not found. I have reade the Documentation and as far as i have observed i am doing it by the github standards. Can anyone Help with this issues?
As illustrated in this python script, the header should be using 'token' not Bearer'
headers = {
'Content-Type':'application/json',
'Authorization': 'token %s' % token,
}
(That script doesn't use curl, but give an idea of the header)
For curl queries, see this curl POST tutorial:
curl -H "Authorization: token OAUTH-TOKEN"
And the POST message must be complete as well (as in this python script)
issue = {'title': title,
'body': body,
'assignee': assignee,
'milestone': milestone,
'labels': labels}
# Add the issue to our repository
r = session.post(url, json=issue)
(again, not curl, but gives you an example of the body)
Go to "Edit personal access token" page, checkout the "Select scopes" session.
Make sure the token has been granted required access right.
I encountered similar case when trying to create public repo with 'Authorization: token ...' header.

Resources