The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Basic authentication with Abdera client

Highlighted
New Member

Basic authentication with Abdera client

Hi all,



I'm trying to update my Abdera client application to use Basic authentication. Here is my basic code for initializing the client:



Abdera abdera = new Abdera();

AbderaClient client = new AbderaClient(abdera);

AbderaClient.registerTrustManager(); // needed for SSL

AbderaClient.registerScheme(AuthPolicy.BASIC, BasicScheme.class);

client.setAuthenticationSchemePriority(AuthPolicy.BASIC);

client.usePreemptiveAuthentication(false);

client.addCredentials(AuthScope.ANY_HOST, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME, new UsernamePasswordCredentials(apiKey + "%" + userName, password));



When I use the client to PUT however I get a 401: Unauthorized error. I've tested the same URL and credentials using RESTClient and they work fine. Any suggestions as to why it would not authorize properly?

1 REPLY 1
Highlighted
Moderator

Hi Gerald,   We unfortunately

Hi Gerald,


 


We unfortunately do not have any abdera experts on hand who may have more intimate knowledge of this language.  However, I believe that the correct syntax for ading a credential should be as follows (this could be the cause of your 401 unauthorized):


 


client.addCredentials("http://api.constantcontact.com", "realm", "basic", new UsernamePasswordCredentials(apiKey + "%" + userName, password));



The realm option should not matter in this case, however the domain and the scheme are important to set.  I am unsure how the headers are set for requests made with ANY_HOST and ANY_SCHEME and this may affect whether or not the API will accept the connection.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured