Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass credentials to Sonar API calls?

Tags:

api

sonarqube

When I try to call:

https://sonar.mydomain.com/api/resources?resource=com.mydomain.project:MY&metrics=ncloc&format=json

I get

{"err_code":401,"err_msg":"Unauthorized"}

How do I pass my credentials?

like image 881
pbx Avatar asked Mar 07 '14 07:03

pbx


People also ask

How do I pass API credentials?

You can pass in the API Key to our APIs either by using the HTTP Basic authentication header or by sending an api_key parameter via the query string or request body. If you use our client library CARTO. js, you only need to follow the authorization section and we will handle API Keys automatically for you.

How do I authenticate an API call?

Authenticate API requests using basic authentication with your email address and password, with your email address and an API token, or with an OAuth access token. All methods of authentication set the authorization header differently. Credentials sent in the payload or URL are not processed.

How do I add authentication to SonarQube?

User. Multiple integrations that allow the delegation of authentication are available (see the Plugin Version Matrix), but you can manually create and edit users at Settings > Security > Users. For manually-created users, login and password can be set at creation. Manually-created users can edit their passwords.

How can I call SonarQube API?

Calling the Sonar API. In order to access the API, you need an access token. The access token must be generated inside Sonar, so log in to your instance and navigate to your profile page. Up at the top right, click the arrow next to Update Info and select Create Personal Access Token.


1 Answers

According to the newest documentation said: SonarQube now support two way authentication:

  • User Token

This is the recommended way. Token is sent via the login field of HTTP basic authentication, this way will be more safety, without any password. For more information about how to generate a token, please visit this page User Token. Use curl send request like this:

curl -u THIS_IS_MY_TOKEN: https://sonarqube.com/api/user_tokens/search
# note that the colon after the token is required in curl to set an empty password 
  • HTTP Basic Access

Login and password are sent via the standard HTTP Basic fields:

curl -u MY_LOGIN:MY_PASSWORD https://sonarqube.com/api/user_tokens/search
like image 117
codezjx Avatar answered Sep 19 '22 19:09

codezjx