I’m currently writing a little NetBeans Plugin with DukeScript. The Plugin allows you to show,
filter and sort the issues of a Bitbucket project inside NetBeans. For this
I need to make authenticated calls to the Bitbucket API.
Here’s how I do that.
In DukeScript we’re using @OnReceive
to connect to a REST endpoint. Here’s the example from the @OnReceive Javadoc:
If the REST-Endpoint requires basic authentication, we’ll need to
somehow get hold of a username and password. Let’s assume we get them from a form
and store them in the viewmodel:
We’ll use the HTTP-Authorization-header to authenticate. For this, we need to
encode username and password in a String. I’ve written a little function for that:
Now we add the Authorization Header to the call by declaring it in the Annotation:
The generated method will now have an additional parameter, so the call changes to:
That’s how you add basic authentication to DukeScript.