Package 'icesConnect'

Title: Provides User Tokens for Access to ICES Web Services
Description: Provides user tokens for ICES web services that require authentication and authorization. Web services covered by this package are ICES VMS database, the ICES DATSU web services, and the ICES SharePoint site <https://www.ices.dk/data/tools/Pages/WebServices.aspx>.
Authors: Colin Millar [aut, cre]
Maintainer: Colin Millar <[email protected]>
License: GPL-3
Version: 1.1.0
Built: 2024-12-09 05:44:36 UTC
Source: https://github.com/ices-tools-prod/icesConnect

Help Index


clear_token

Description

Deletes the token from the key ring.

Usage

clear_token(username = getOption("ices.username"))

Arguments

username

the ices username that you require a token for, Default: getOption("ices.username")

Value

no return value

See Also

username

Examples

## Not run: 
clear_token()

## End(Not run)

Decode token

Description

Decodes the token to allow inspection of claims

Return the expiration date of the token

What user is this token for

Usage

decode_token(jwt = ices_token(), formatted = TRUE)

token_expiration(jwt = ices_token())

token_user(jwt = ices_token())

Arguments

jwt

a javascript web token got by running ices_token()

formatted

should formatted output be returned

Value

list of claims

POSIXct date time

string, user name

See Also

username

username

username

Examples

## Not run: 
decode_token()

## End(Not run)

## Not run: 
token_expiration()

## End(Not run)

## Not run: 
token_user()

## End(Not run)

Get a url

Description

Get a url, optionally using an ICES authentication token

Usage

ices_get(
  url,
  retry = TRUE,
  quiet = FALSE,
  verbose = FALSE,
  content = TRUE,
  use_token = FALSE
)

Arguments

url

the url to get.

retry

should the get request be retried if first attempt fails? default TRUE.

quiet

should all messages be suppressed, default FALSE.

verbose

should verbose output form the http request be returned? default FALSE.

content

should content be returned, or the full http reponse? default TRUE, i.e. content is returned by default.

use_token

should an authentication token be sent with the request?

Value

content or an http response.

See Also

sag_api builds a SAG web service url.

icesSAG-package gives an overview of the package.

Examples

## Not run: 
ices_get(sag_api("StockList", year = 2022))

## End(Not run)

ices_request_jwt

Description

Perform a get request to a url using a javascript web token for authentication

Usage

ices_get_jwt(
  url,
  username = NULL,
  retry = TRUE,
  quiet = FALSE,
  verbose = FALSE,
  jwt = NULL
)

ices_post_jwt(
  url,
  body = list(),
  encode = "json",
  username = NULL,
  retry = TRUE,
  quiet = FALSE,
  verbose = FALSE,
  jwt = NULL
)

ices_patch_jwt(
  url,
  body = list(),
  encode = "json",
  username = NULL,
  retry = TRUE,
  quiet = FALSE,
  verbose = FALSE,
  jwt = NULL
)

ices_request_jwt(
  type = c("GET", "POST", "PATCH"),
  url,
  body = NULL,
  encode = c("multipart", "form", "json", "raw"),
  username = NULL,
  retry = TRUE,
  quiet = FALSE,
  verbose = FALSE,
  jwt = NULL
)

Arguments

url

the url to make the request to

username

the ices username to perform the request as, Default: getOption("ices.username")

retry

if initial request fails, should a retry be made, Default: TRUE

quiet

suppress informative messages to the console

verbose

should the http request return verbose output

jwt

option to supply a token bypassing the ices_token() route, if "" no token is used

body

optional body of request

encode

If the body is a named list, how should it be encoded?

type

the type of request to make, GET, POST or PATCH

Value

httr response object

See Also

ices_token GET,add_headers,stop_for_status,status_code

Examples

## Not run: 
# this function is interactive and asks the user for a password
ices_request_jwt("GET", "https://taf.ices.dk/vms/api/gearwidths")
ices_get_jwt("https://taf.ices.dk/vms/api/gearwidths")

## End(Not run)

ices_token

Description

Stores a user token in the system keyring

Usage

ices_token(username = NULL, password = NULL, refresh = FALSE, ...)

Arguments

username

the ices username that you require a token for, Default: NULL, which results in getOption("ices.username")

password

the ices username that you require a token for, Default: NULL, which results in a dialogue box request for the password

refresh

should the token be refreshed to update new claims for example

...

not yet used

Value

character scalar, the token

See Also

username

Examples

## Not run: 
ices_token()

## End(Not run)

Set your ICES username

Description

Set the ICES user or logon name that will be used for requests

Usage

set_username(username)

Arguments

username

the ices username you use to login to SharePoint for example.

Details

To set this permanently, add the line: options(ices.username = "your ices user name") to your '.Rprofile' file, see, usually '~/.Rprofile', see Startup for more information.

Value

invisible value: the previous username that was set

See Also

options getOption

Examples

set_username("myusername")