Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_tokenauth.sas File Reference

Get initial Refresh and Access Tokens. More...

Go to the source code of this file.

Detailed Description

Before a Refresh Token can be obtained, the client must be registered by an administrator. This can be done using the mv_registerclient macro, after which the user must visit a URL to get an additional code (if using oauth).

That code (or username / password) is used here to get the Refresh Token (and an initial Access Token). THIS MACRO CAN ONLY BE USED ONCE - further access tokens can be obtained using the mv_gettokenrefresh macro.

Access tokens expire frequently (every 10 hours or so) whilst refresh tokens expire periodically (every month or so). This is all configurable.

Usage:

filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;


%mv_registerclient(outds=clientinfo)

%mv_tokenauth(inds=clientinfo,code=LD39EpalOf)

A great article for explaining all these steps is available here:

https://blogs.sas.com/content/sgf/2019/01/25/authentication-to-sas-viya/

Parameters
inds=A dataset containing client_id, client_secret, and auth_code
outds=A dataset containing access_token and refresh_token
client_id=The client name
client_secret=client secret
grant_type=valid values are "password" or "authorization_code" (unquoted). The default is authorization_code.
code=If grant_type=authorization_code then provide the necessary code here
user=If grant_type=password then provide the username here
pass=If grant_type=password then provide the password here
access_token_var=The global macro variable to contain the access token
refresh_token_var=The global macro variable to contain the refresh token
base_uri=The Viya API server location
Version
VIYA V.03.04
Author
Allan Bowe @source https://github.com/sasjs/core

Dependencies

Definition in file mv_tokenauth.sas.