Skip to content

authentication

Deva Kumar edited this page Jun 15, 2020 · 1 revision

Authentication

restaf supports sessions authenticated in one of these OAUTH2 flows

  1. PASSWORD flow
  2. AUTHORIZATION_CODE flow
  3. IMPLICIT flow

There are scenarios where the token might already exist. restaf will accept this token also.

logon method

The store.logon method establishes connection with SAS Viya.

  await store.logon(payload);

The rest of this page discusses the form of payload for the various authentication flows

PASSWORD flow

Password flow is typically used in cli's and nodejs applications.

       let  payload = {
            authType    : 'password',
            host        : 'http://your-viya-server',
            user        : username,
            password    : user password,
            clientID    : clientid,  /* get this from your admin */
            clientSecret: clientsecret /* get this from your admin */
            } );
        store.logon  ( payload )
            .then ( () => ...do whatever your app does ...)
            .catch( err => ...do recovery ... )

Authorization_code flow

In a browser session authenticated with authorization flow use the following payload

    let payload = {
        authType: 'server',
        host    : 'http://your-viya-server'
    };
    store.logon  ( payload )
            .then ( () => ...do whatever your app does ...)
            .catch( err => ...do recovery ... )

A note on using restaf in VA's Data Driven Component(DDC) or web content

When your app is running in a DDC the payload should be as follows:

    let payload = {
        authType: 'server',
        host    : window.location.origin
    };
    store.logon  (payload)
            .then ( () => ...do whatever your app does ...)
            .catch( err => ...do recovery ... )

Implicit flow

In your logon.html make this call.

        let payload = {
            host        : <Viya server host (ex: http://my.example.com)
            clientID    : <clientid>
            redirect    : <your redirect uri>,
            authType    : 'implicit',
        };

        store.logon  (payload)
          .catch(err => ...do recovery ... )

This will result in the user being prompted for username and password.If successful the user will be redirected the redirect uri - which is the main entry of the application.

In the main entry of your application you will make the following call:

store.logon(null)
.then(...)

restaf will parse the url for the token and save it in the store.

Using an existing token

There are situations where a valid token might exist(ex: you have created a long-lived token for running jobs as part of your CI/CD process) In that case use the following payload to store.logon

        store.logon( {
            authType: 'token',
            host: "<your viya server>',
            token: "<your token>"
        });

Accessing authentication information

If for some reason you need information on the authenticatiin for the session make the following call:

    let c = store.connection();

The connection method returns information on the current connection.

Sample output:

{
    "type": "trusted",
    "host": "http://your-viya-host",
    "tokenType": "bearer",
    "token": "... your Oauth token ..."
}
Clone this wiki locally