Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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
[in]inds=A dataset containing client_id, client_secret, and auth_code
[in]outds=A dataset containing access_token and refresh_token
[in]client_id=The client name
[in]client_secret=client secret
[in]grant_type=valid values are "password" or "authorization_code" (unquoted). The default is authorization_code.
[in]code=() If grant_type=authorization_code then provide the necessary code here
[in]user=If grant_type=password then provide the username here
[in]pass=If grant_type=password then provide the password here
[in]access_token_var=(ACCESS_TOKEN) The global macro variable to contain the access token
[in]refresh_token_var=(REFRESH_TOKEN) The global macro variable to contain the refresh token
[in]base_uri=The Viya API server location
Version
VIYA V.03.04
Author
Allan Bowe, source: https://github.com/sasjs/core

SAS Macros

Definition in file mv_tokenauth.sas.