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?
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.
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.
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.
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.
According to the newest documentation said: SonarQube now support two way authentication:
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
Login and password are sent via the standard HTTP Basic fields:
curl -u MY_LOGIN:MY_PASSWORD https://sonarqube.com/api/user_tokens/search
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With