Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
cwclientlibjs
Commits
c0c19811a853
Commit
ef264f2a
authored
Oct 01, 2020
by
Henri Cazottes
Browse files
doc(Readme): Add signed request example
parent
8ead09c2a845
Changes
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
c0c19811
...
...
@@ -34,6 +34,9 @@ A RqlClient relies on an HttpClient. Two implementations are available
[
CwSimpleHttpClient
](
src/client.ts#L332
)
and
[
CwSigningHttpClient
](
src/client.ts#L462
)
.
### CwSimpleHttpClient: anonymous request
[
CwSimpleHttpClient
](
src/client.ts#L332
)
requires a baseUrl (the base url of a
cubicweb instance). A boolean can be added to allow cross origin requests. The
CwSimpleHttpClient can perform a doLogin(login,password) operation on the
...
...
@@ -42,11 +45,6 @@ issues](#known-issues)). It can also be transformed into a CwSigningHttpClient
(toSigningClient()) after a doLogin() operation. It requires that the CubicWeb
user has at least an enabled token linked to his/her account.
[
CwSigningHttpClient
](
src/client.ts#L462
)
requires a baseUrl (the base url of a
cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each
request will contain a Authorization header with the connection token and its
hashed value.
```
javascript
import
{
providers
,
client
}
from
'
@logilab/cwclientlibjs
'
;
...
...
@@ -80,6 +78,33 @@ rqlClient.transactionV2([query]).then(res => {
});
```
### CwSigningHttpClient: authenticated requests.
[
CwSigningHttpClient
](
src/client.ts#L462
)
requires a baseUrl (the base url of a
cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each
request will contain an Authorization header with the connection token and its
hashed value.
These tokens are managed on your CubicWeb instance under Profile > Actions > Add
> Authentication Token.
```
javascript
import
{
providers
,
client
}
from
'
@logilab/cwclientlibjs
'
;
// url is the base url of your cubicweb instance
const
url
=
'
http://my-cubicweb-instance-base-url/
'
;
const
rqlClient
=
new
client
.
CwRqlClient
(
new
client
.
CwSimpleHttpClient
(
url
,
"
my-token-name
"
,
"
1a2b3c4d5e6f...
"
)
);
const
query
=
'
Any X, Y WHERE X is BlogEntry, X entry_of Y
'
;
rqlClient
.
queryRows
(
query
).
then
(
res
=>
{
console
.
log
(
res
);
// [[123,1], [234, 2]]
});
```
## Providers.ts
The
[
provider
](
src/providers.ts
)
namespace provides two main objects:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment