On this page:
3.1 Module oauth2/  storage/  config.
get-current-user-name
get-current-user-name/  bytes
get-preference
set-preference!
load-preferences
save-preferences
3.2 Module oauth2/  storage/  clients.
get-client
set-client!
load-clients
save-clients
3.3 Module oauth2/  storage/  tokens.
get-services-for-user
get-token
set-token!
load-tokens
save-tokens
7.8

3 Configuration and Client Persistence

The three modules described here allow the persistence of configuration between execution of tools or services using this package.

By default the files described below are stored in a directory ".oauth2.rkt" within the directory specified by find-system-path with the kind value 'home-dir.

3.1 Module oauth2/storage/config.

 (require oauth2/storage/config) package: simple-oauth2

This module provides a very simple get/put interface for configuration settings used by the package in general. The following table describes the currently used settings, with their types and default values.

key

type

default value

'cipher-impl

(listof symbol?)

'(aes gcm)

'cipher-key

bytes?

generated

'cipher-iv

bytes?

generated

'redirect-host-type

symbol?

'localhost

'redirect-host-port

exact-positive-integer?

8080

'redirect-path

string?

"/oauth/authorization"

'redirect-ssl-certificate

(or/c false/c path-string?)

#f

'redirect-ssl-key

(or/c false/c path-string?)

#f

The values for 'cipher-impl, 'cipher-key, and 'cipher-iv should not be modified by hand. The 'cipher-impl value determines which implementation is used to generate the 'cipher-key and 'cipher-iv which are used to encrypt/decrypt secrets in the clients and tokens files.

The values starting with 'redirect- represent the configuration for the internal web server required to host the OAuth redirect URI. The two SSL settings are paths to the corresponding files containing the certificate and key.

Retrieve the user name for the currently logged-in user, this is used by default as the on-belhalf-of user in authentication calls.

procedure

(get-preference key)  any/c

  key : symbol?
Retrieve a preference value using one of the symbols listed in the table above.

procedure

(set-preference! key value)  void/c

  key : symbol?
  value : any/c
Set a preference value for one of the keys listed in the table above.

procedure

(load-preferences)  boolean?

procedure

(save-preferences)  boolean?

Load and save the preference file, by default a file is loaded when the module is imported for the first time. If no file is found a new one is created with the default values listed in the table above.

3.2 Module oauth2/storage/clients.

 (require oauth2/storage/clients) package: simple-oauth2

This module provides a persistence layer for client configurations (see struct client?). The value for client-secret will be encryted during set-client! and decrypted during get-client and therefore will alway be stored in encrypted form.

procedure

(get-client service-name)  client?

  service-name : string?
Retrieve a client configuration from it’s service name.

procedure

(set-client! a-client)  void/c

  a-client : clientl?
Store a client configuration as a mapping from service name (see client-service-name to client.

procedure

(load-clients)  boolean?

procedure

(save-clients)  boolean?

Load and save the clients file, by default a file is loaded when the module is imported for the first time.

3.3 Module oauth2/storage/tokens.

 (require oauth2/storage/tokens) package: simple-oauth2

This module provides a persistence layer for authentication tokens (see struct token?). The values for token-access-token and token-refresh-token will be encryted during set-token! and decrypted during get-token and therefore will alway be stored in encrypted form.

procedure

(get-services-for-user user-name)  (listof string?)

  user-name : string?
Retrieve a list of service names that have tokens for the given user name.

procedure

(get-token user-name service-name)  token?

  user-name : string?
  service-name : string?
Retrieve a token retrieved from service-name, on behalf of the user user-name.

procedure

(set-token! user-name service-name a-token)  void/c

  user-name : string?
  service-name : string?
  a-token : token?
Store a token retrieved from service-name, on behalf of the user user-name.

procedure

(load-tokens)  boolean?

procedure

(save-tokens)  boolean?

Load and save the tokens file, by default a file is loaded when the module is imported for the first time.