Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting unauthorised error #16

Closed
zedherle opened this issue Sep 28, 2020 · 7 comments
Closed

getting unauthorised error #16

zedherle opened this issue Sep 28, 2020 · 7 comments

Comments

@zedherle
Copy link

zedherle commented Sep 28, 2020

Please read these guidelines before opening an issue.

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

I have put my client credentials in the application.prop like below

cloudant.url=https://ca5401d9-c380-428e-acd9-bf4621b73e26-bluemix.cloudantnosqldb.appdomain.cloud
cloudant.username=***************
cloudant.password=************

and then i have autowired as mentioned in the readme of this repository
@Autowired
private CloudantClient client;

through my controller i am calling this method to see if its working
public List getAllDbs() {

    return client.getAllDbs();
}

2. What you expected to happen

I am supposed to be getting right results with list of dbs available.

3. What actually happened

Currently it is throwing me errors like this below,
com.cloudant.client.org.lightcouch.CouchDbException: 401 Unauthorized at https://2a6085c6-394e-4a69-8074-6334f6b0c91a-bluemix.cloudant.com:443/_all_dbs. Error: unauthorized. Reason: one of _all_dbs, _admin, server_admin is required for this request.

But i do have right access. Not sure which part i am doing it wrong.

Environment details

  • Java version including vendor and platform

    1.8

  • Spring framework or boot version

    com.cloudant
    cloudant-spring-boot-starter
    0.0.4
@emlaver
Copy link
Contributor

emlaver commented Sep 28, 2020

Hi @zedherle, the URL in the CouchDbException error message (https://2a6085c6-394e-4a69-8074-6334f6b0c91a-bluemix.cloudant.com:443/) doesn't match the URL in your application.properties (https://ca5401d9-c380-428e-acd9-bf4621b73e26-bluemix.cloudantnosqldb.appdomain.cloud). Could you verify that your code is getting the expected URL, username, and password from your application.properties file?

@emlaver emlaver self-assigned this Sep 28, 2020
@zedherle
Copy link
Author

zedherle commented Oct 2, 2020

Hi, i looked at the app property, indeed its a wrong url... but it should ideally pick it from there right? however i see them as "unused property", am i missing something? i am using idea community edition.

cloudant.url=https://ca5401d9-c380-428e-acd9-bf4621b73e26-bluemix.cloudantnosqldb.appdomain.cloud/_all_dbs
cloudant.username=
cloudant.password=

@zedherle
Copy link
Author

zedherle commented Oct 2, 2020

i am infact getting this error : 2020-10-02 16:40:25.245 ERROR 13756 --- [nio-8081-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.cloudant.client.org.lightcouch.CouchDbException: Error retrieving server response at https://null.cloudant.com:443/_all_dbs.] with root cause

should the property be cloudant.account or cloudant.url ? - i tried both though... (documentation has both as well)

@ricellis
Copy link
Member

ricellis commented Oct 2, 2020

Since you have the cloudantnosqldb.appdomain.cloud domain you should use cloudant.url
i.e.
cloudant.url=https://ca5401d9-c380-428e-acd9-bf4621b73e26-bluemix.cloudantnosqldb.appdomain.cloud

cloudant.account takes the account and inserts it into https://<account>.cloudant.com
so the expectation would be something like
cloudant.account=ca5401d9-c380-428e-acd9-bf4621b73e26-bluemix (but I have no idea if that account name is valid with cloudant.com domain, so just use the cloudant.url as above.

@zedherle
Copy link
Author

zedherle commented Oct 5, 2020

for somehow, it does not work. Do you have any sample code/git reference for cloudant db connection so that i can verify. i searched for it and couldn't get. Am i doing app.properties right?

@zedherle
Copy link
Author

zedherle commented Oct 5, 2020

however i had to do via Cloudant builder to make that work. btw - does app property has iam key attribute also?

@Bean
    public CloudantClient builder() {
        CloudantClient client = null;
        try {
            client =  ClientBuilder.url(url)
                    .iamApiKey("******")
                    .build();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
       return client;
    }

@ricellis
Copy link
Member

ricellis commented Oct 5, 2020

Am i doing app.properties right?

Just to be clear the configuration file name is application.properties - I've noticed it called a few other things in this issue (application.prop and app.properties), which I'm assuming are just abbreviations, but I want to make sure we're not missing something simple!

should the property be cloudant.account or cloudant.url ? - i tried both though... (documentation has both as well)

You're using cloudant.url now right? cloudant.account in the documentation example is only valid with that override example shown with an additional @Value("${cloudant.account}") annotated field.

does app property has iam key attribute also?

No, IAM properties have not been added to this lib. You can open another issue to request this feature if you want it.
Currently only Basic auth credentials or Cloudant legacy API keys can be supplied via the cloudant.username and cloudant.password properties. As a workaround you can add a property to your override bean as demonstrated in the README documentation.

Note that if you are using a legacy Cloudant API key it will not be authorized to getAllDbs() - they do not have account level permissions and can only perform actions on specific databases.

@ricellis ricellis closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants