Discussion:
[Chicken-users] http-client help needed with basic authorization
Jörg F. Wittenberger
2018-08-20 12:47:25 UTC
Permalink
I'm trying to use the http-client to talk to a Jira installation.

Without much success.

Jira is documented to support Basic authentication. However it defaults to
and advertices OAuth. For the case at hand, a script reading some data, it
OAuth looks like wasteful overhead.

The idea is to supply an "Authorization" header right with the request.

Any hints welcome.

So far I have this:

(define (insightc-query!2 uri . more)
(define (basic-auth username pw)
(string-append
"Basic "
(basic-auth-param-subunparser `((username . ,username) (password .
,pw))))
#;`#(Basic ((username . ,username) (password . ,pw)))
#;`#(Basic (,(basic-auth-param-subunparser `((username . ,username)
(password . ,pw)))))
)
(let* ((uri (update-uri uri host: "localhost" port: 7070 path: (append
(uri-path uri) more)))
(username "jwi")
(pw (call-with-input-file ".password" read))
(hdr (headers `((authorization ,(basic-auth username pw)))))
(req (make-request uri: uri headers: hdr)))
(call-with-response req (lambda (x) #f) insightc-response-handler)))

Error: (unparse-headers) could not unparse "Authorization" header (#("Basic
and... ...=" Error: (unparse-headers) could not unparse "Authorization"
header (#("Basic and... ...="
Call history:

intarweb.scm:724: ##sys#print
Peter Bex
2018-08-20 13:05:31 UTC
Permalink
Post by Jörg F. Wittenberger
I'm trying to use the http-client to talk to a Jira installation.
Without much success.
Jira is documented to support Basic authentication. However it defaults to
and advertices OAuth. For the case at hand, a script reading some data, it
OAuth looks like wasteful overhead.
The idea is to supply an "Authorization" header right with the request.
http-client comes with built-in basic auth support. Just put a username
and password in the URL's authorization component.
Post by Jörg F. Wittenberger
Any hints welcome.
(define (insightc-query!2 uri . more)
(define (basic-auth username pw)
(string-append
"Basic "
(basic-auth-param-subunparser `((username . ,username) (password .
,pw))))
#;`#(Basic ((username . ,username) (password . ,pw)))
#;`#(Basic (,(basic-auth-param-subunparser `((username . ,username)
(password . ,pw)))))
)
(let* ((uri (update-uri uri host: "localhost" port: 7070 path: (append
(uri-path uri) more)))
(username "jwi")
(pw (call-with-input-file ".password" read))
(hdr (headers `((authorization ,(basic-auth username pw)))))
(req (make-request uri: uri headers: hdr)))
(call-with-response req (lambda (x) #f) insightc-response-handler)))
Error: (unparse-headers) could not unparse "Authorization" header (#("Basic
and... ...=" Error: (unparse-headers) could not unparse "Authorization"
header (#("Basic and... ...="
intarweb.scm:724: ##sys#print
If you want to pass a raw string through the request unparser, convert it
to a blob. Then it will be taken as-is, iirc.

Cheers,
Peter
Jörg F. Wittenberger
2018-08-20 17:35:32 UTC
Permalink
Post by Peter Bex
Post by Jörg F. Wittenberger
I'm trying to use the http-client to talk to a Jira installation.
Without much success.
Jira is documented to support Basic authentication. However it defaults
to and advertices OAuth. For the case at hand, a script reading some
data, it OAuth looks like wasteful overhead.
The idea is to supply an "Authorization" header right with the request.
http-client comes with built-in basic auth support. Just put a username
and password in the URL's authorization component.
That's what I tried first. :-/
Post by Peter Bex
Post by Jörg F. Wittenberger
Any hints welcome.
(define (insightc-query!2 uri . more)
(define (basic-auth username pw)
(string-append
"Basic "
(basic-auth-param-subunparser `((username . ,username) (password .
,pw))))
#;`#(Basic ((username . ,username) (password . ,pw)))
#;`#(Basic (,(basic-auth-param-subunparser `((username . ,username)
(password . ,pw)))))
)
(let* ((uri (update-uri uri host: "localhost" port: 7070 path: (append
(uri-path uri) more)))
(username "jwi")
(pw (call-with-input-file ".password" read))
(hdr (headers `((authorization ,(basic-auth username pw)))))
(req (make-request uri: uri headers: hdr)))
(call-with-response req (lambda (x) #f) insightc-response-handler)))
Error: (unparse-headers) could not unparse "Authorization" header
(#("Basic and... ...=" Error: (unparse-headers) could not unparse
"Authorization" header (#("Basic and... ...="
intarweb.scm:724: ##sys#print
If you want to pass a raw string through the request unparser, convert it
to a blob. Then it will be taken as-is, iirc.
Ah, great, that might do the trick. Will try tomorrow.
Post by Peter Bex
Cheers,
Peter
Loading...