{"componentChunkName":"component---src-templates-template-tsx","path":"/sasjs-auth-login","result":{"data":{"site":{"meta":{"title":"SAS Apps - Unleash Your Analytics","description":"Custom Interfaces to the world's most powerful Analytics Platform","siteUrl":"https://sasapps.io","author":"Allan Bowe","twitter":"","adsense":""}},"post":{"id":"1e56839d-95e6-55cb-81c0-9be4ff968908","html":"<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 750px; margin-bottom: 1.0725rem;\"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 100%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQFAv/EABYBAQEBAAAAAAAAAAAAAAAAAAMBAv/aAAwDAQACEAMQAAAB2ormsYLWMVABuhL/AP/EABsQAAIDAAMAAAAAAAAAAAAAAAABAgMREBIh/9oACAEBAAEFAnpZ2JrJHo6IyZnH/8QAGBEAAgMAAAAAAAAAAAAAAAAAAAEQERP/2gAIAQMBAT8Baszc/wD/xAAYEQACAwAAAAAAAAAAAAAAAAAAARARE//aAAgBAgEBPwFOjRT/AP/EABwQAAEDBQAAAAAAAAAAAAAAAAEAAhEQICExcf/aAAgBAQAGPwIwssLuI00iTNn/xAAcEAEBAAICAwAAAAAAAAAAAAABABEhMVFBYXH/2gAIAQEAAT8heGnPizK4/QcPsAgQ6ZFY9Fs7L3IQLi//2gAMAwEAAgADAAAAEM/v/wD/xAAZEQABBQAAAAAAAAAAAAAAAAAAARARIUH/2gAIAQMBAT8QAstGt//EABkRAAIDAQAAAAAAAAAAAAAAAAABECFBUf/aAAgBAgEBPxDiEtWZH//EABsQAQADAQEBAQAAAAAAAAAAAAEAESExYZGh/9oACAEBAAE/EDlaTKPfYqeAGrjYIvnOp4xW0JzWUWAjuMe5XsoEc2n7K90/YAKOT//Z'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"SASjs CLI Auth Login\"\n        title=\"SASjs CLI Auth Login\"\n        src=\"/static/7399692f243327f85fff0a76e28b4a2b/acb04/sasjs-auth-login.jpg\"\n        srcset=\"/static/7399692f243327f85fff0a76e28b4a2b/bc01b/sasjs-auth-login.jpg 188w,\n/static/7399692f243327f85fff0a76e28b4a2b/bf173/sasjs-auth-login.jpg 375w,\n/static/7399692f243327f85fff0a76e28b4a2b/acb04/sasjs-auth-login.jpg 750w,\n/static/7399692f243327f85fff0a76e28b4a2b/72e01/sasjs-auth-login.jpg 1024w\"\n        sizes=\"(max-width: 750px) 100vw, 750px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>The SASjs CLI has always required a registered OAuth client and secret to authenticate against SAS Viya. If you are a developer who just wants to run a SAS program from the command line, getting an administrator to register an OAuth client for you is friction you do not need. The new <code class=\"language-text\">sasjs auth login</code> command removes that barrier - you log in with your regular SAS username and password, and the CLI handles the rest.</p>\n<h2>What it does</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">sasjs auth login -t myviyatarget</code></pre></div>\n<p>That is it. You are prompted for your SAS username and password (the password input is masked), the CLI exchanges them for an access/refresh token pair, verifies the token, and persists it. From that point on, the stored token can be used by any command that accepts an access token - <code class=\"language-text\">sasjs run</code>, <code class=\"language-text\">sasjs deploy</code>, <code class=\"language-text\">sasjs job execute</code>, <code class=\"language-text\">sasjs flow</code>, <code class=\"language-text\">sasjs fs</code>, <code class=\"language-text\">sasjs request</code>, <code class=\"language-text\">sasjs context</code>, <code class=\"language-text\">sasjs folder</code>, <code class=\"language-text\">sasjs test</code>. No client or secret is needed for the initial login or for silent token refreshes (the built-in <code class=\"language-text\">sas.cli</code> public client handles those).</p>\n<h2>Why it matters</h2>\n<p>Before this feature, authenticating to Viya from the SASjs CLI meant:</p>\n<ol>\n<li>Asking a SAS administrator to register an OAuth client in SAS Viya</li>\n<li>Obtaining the CLIENT ID and CLIENT SECRET</li>\n<li>Running <code class=\"language-text\">sasjs auth</code> (or <code class=\"language-text\">sasjs add cred</code>), which uses the authorisation code flow - you visit a URL in your browser, sign in, grant access, and paste back an authorisation code</li>\n</ol>\n<p>That is fine for production CI pipelines, but painful for a developer who just wants to test something quickly on a demo Viya instance. The new <code class=\"language-text\">sasjs auth login</code> command uses the OAuth2 resource owner password grant against the built-in, secret-less <code class=\"language-text\">sas.cli</code> public client - the same client the official SAS Viya CLI uses. No client registration, no secret, no browser redirect.</p>\n<h2>How it works</h2>\n<p>Under the hood, <code class=\"language-text\">sasjs auth login</code> does the following:</p>\n<ol>\n<li><strong>Password grant request</strong> - sends a POST to <code class=\"language-text\">/SASLogon/oauth/token</code> with <code class=\"language-text\">grant_type=password</code>, your username, and your password, authenticated with a Basic auth header for the <code class=\"language-text\">sas.cli</code> client (which has no secret).</li>\n<li><strong>Token verification</strong> - calls <code class=\"language-text\">GET /identities/users/@currentUser</code> with the access token to confirm it is valid and to identify the logged-in user.</li>\n<li><strong>Token persistence</strong> - saves the access token and refresh token to the same locations as the existing <code class=\"language-text\">sasjs auth</code> flow: <code class=\"language-text\">.env.[target name]</code> for local targets, <code class=\"language-text\">~/.sasjsrc</code> for global targets.</li>\n<li><strong>Automatic refresh</strong> - when the access token is close to expiry, the CLI silently refreshes it using the stored refresh token (again via the <code class=\"language-text\">sas.cli</code> client). No client/secret is needed for the refresh either.</li>\n</ol>\n<p>Viya refresh tokens are single-use and rotate on every refresh. The CLI persists the rotated pair automatically after every refresh - so the next CLI invocation always reads the latest valid pair, and you never end up with a stale refresh token.</p>\n<h2>Quick start</h2>\n<p>First, make sure you have a target configured for your Viya server. If you do not have one yet, create one with the interactive wizard:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">sasjs <span class=\"token function\">add</span></code></pre></div>\n<p>The command prompts you for the target name, server type (pick SAS Viya), server URL, and app location. You can skip the authentication step at the end - <code class=\"language-text\">sasjs auth login</code> will handle that separately.</p>\n<p>Then log in:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">sasjs auth login -t myviyatarget\n<span class=\"token comment\"># Please enter your SAS username: viyademo01</span>\n<span class=\"token comment\"># Please enter your SAS password: ********</span>\n<span class=\"token comment\"># Logged in as viyademo01 (Viya Demo User) on https://your-viya-server.com.</span></code></pre></div>\n<p>Now run any command:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">sasjs run myprogram.sas -t myviyatarget</code></pre></div>\n<p>When the access token expires (12 hours by default, though some estates configure shorter TTLs for the <code class=\"language-text\">sas.cli</code> client), the CLI will silently refresh it. If the refresh token itself expires, just run <code class=\"language-text\">sasjs auth login -t myviyatarget</code> again.</p>\n<h2>Security notes</h2>\n<ul>\n<li><strong>The password is never persisted.</strong> It is used only to mint the token pair and is not written to any file. The password stays in memory for the lifetime of the short-lived CLI process, which exits within seconds.</li>\n<li><strong>No <code class=\"language-text\">--password</code> command-line flag exists.</strong> Passing a password as a command-line argument would leak it via shell history and process listings (<code class=\"language-text\">ps</code>). The CLI deliberately does not offer this option.</li>\n<li><strong>Refresh tokens are rotated and stored.</strong> Because Viya refresh tokens are single-use, the CLI persists the new pair after every refresh. This is handled automatically.</li>\n<li><strong><code class=\"language-text\">--insecure</code> flag for self-signed certs.</strong> If your Viya server uses self-signed certificates, pass <code class=\"language-text\">--insecure</code> (or <code class=\"language-text\">-i</code>) to bypass TLS validation: <code class=\"language-text\">sasjs auth login -t myviyatarget --insecure</code>. This is not recommended for production.</li>\n</ul>\n<h2>Non-interactive usage (CI pipelines and agents)</h2>\n<p><code class=\"language-text\">sasjs auth login</code> supports both interactive and non-interactive credential input. For CI pipelines and automated environments, there are three non-interactive patterns:</p>\n<p><strong>Environment variables:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token assign-left variable\">SAS_USERNAME</span><span class=\"token operator\">=</span>viyademo01 <span class=\"token assign-left variable\">SAS_PASSWORD</span><span class=\"token operator\">=</span>secret sasjs auth login -t myviyatarget</code></pre></div>\n<p>When both <code class=\"language-text\">SAS_USERNAME</code> and <code class=\"language-text\">SAS_PASSWORD</code> are set, the CLI skips the prompts entirely.</p>\n<p><strong>Password via stdin (avoids shell history leakage):</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"<span class=\"token variable\">$SAS_PASSWORD</span>\"</span> <span class=\"token operator\">|</span> sasjs auth login --password-stdin -t myviyatarget</code></pre></div>\n<p>When <code class=\"language-text\">--password-stdin</code> is set, the password is read from stdin and the username must come from the <code class=\"language-text\">SAS_USERNAME</code> environment variable (stdin is reserved for the password, so interactive prompting is not possible).</p>\n<p><strong>Credential precedence:</strong></p>\n<ul>\n<li>Username: <code class=\"language-text\">SAS_USERNAME</code> env var > interactive prompt (TTY only)</li>\n<li>Password: <code class=\"language-text\">--password-stdin</code> > <code class=\"language-text\">SAS_PASSWORD</code> env var > interactive prompt (TTY only)</li>\n</ul>\n<p>If no TTY is available and no env var or stdin flag supplies the credential, the command throws with a clear message pointing at the env vars or <code class=\"language-text\">--password-stdin</code>. This makes it safe to call from CI pipelines and non-interactive agents.</p>\n<h2>Requirements and limitations</h2>\n<ul>\n<li>The password grant must be enabled for the <code class=\"language-text\">sas.cli</code> client. This is the default on most Viya deployments, but administrators can disable it.</li>\n<li>The account must be a local or LDAP account. <code class=\"language-text\">sasjs auth login</code> cannot work on SSO/SAML/MFA-only estates - those require the browser-based authorisation code flow.</li>\n<li>On a cold Viya estate, the first compute session creation can take several minutes while pods spin up. The first <code class=\"language-text\">sasjs run</code> may appear to hang. Subsequent runs are fast.</li>\n<li>If <code class=\"language-text\">sasjs run</code> fails with a 403 when creating a compute session, your account may not be authorised for the configured compute context. Check the available contexts and update the <code class=\"language-text\">contextName</code> on your target accordingly.</li>\n<li>The password grant is deprecated in OAuth 2.1. This flow is intended for dev/demo estates where obtaining a registered client/secret is impractical. For CI pipelines and production use, a properly registered client/secret (via <code class=\"language-text\">sasjs auth</code>) remains the recommended approach.</li>\n</ul>\n<h2>Backward compatibility</h2>\n<p>The bare <code class=\"language-text\">sasjs auth</code> command (without the <code class=\"language-text\">login</code> subcommand) still works exactly as before - it is an alias for <code class=\"language-text\">sasjs add cred</code> and uses the client/secret authorisation code flow. Nothing changes for existing setups. The <code class=\"language-text\">login</code> subcommand is purely additive.</p>\n<hr>\n<p>The <code class=\"language-text\">sasjs auth login</code> command is available in the latest SASjs CLI release. If you have been putting off trying the SASjs CLI because you did not want to deal with OAuth client registration, this is your excuse to give it a go.</p>\n<!-- Featured image: ~/QubesIncoming/workmodel/proxy.jpeg (provided externally) -->\n<!-- Source LinkedIn post:\n\nAuthenticating to SAS Viya from the command line used to mean getting an admin to register an OAuth client, obtaining a secret, and doing a browser redirect dance.\n\nNot anymore.\n\nThe new \"sasjs auth login\" command lets you log in to Viya with just your SAS username and password. No client, no secret, no browser.\n\nJust:\n- sasjs auth login -t yourtarget\n- Enter username and password\n- Done. Run sasjs run, sasjs request, anything.\n\nIt uses the built-in sas.cli public client (same one the official SAS Viya CLI uses) with the OAuth2 password grant. The password is never stored. Refresh tokens rotate automatically.\n\nCI pipelines are covered too - set SAS_USERNAME and SAS_PASSWORD env vars, or pipe the password with --password-stdin.\n\nOne caveat: it needs a local/LDAP account, so it will not work on SSO/MFA-only estates. For those, the existing client/secret flow is still there.\n\nIf you have been holding off on the SASjs CLI because OAuth client registration was too much hassle, this is for you.\n\n#sas #sasjs #sasviya #devops #cli\n-->","frontmatter":{"title":"SASjs CLI Auth Login - Connect to Viya Without a Client/Secret","featuredImage":{"childImageSharp":{"fixed":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQFAv/EABYBAQEBAAAAAAAAAAAAAAAAAAMBAv/aAAwDAQACEAMQAAAB2ormsYLWMVABuhL/AP/EABsQAAIDAAMAAAAAAAAAAAAAAAABAgMREBIh/9oACAEBAAEFAnpZ2JrJHo6IyZnH/8QAGBEAAgMAAAAAAAAAAAAAAAAAAAEQERP/2gAIAQMBAT8Baszc/wD/xAAYEQACAwAAAAAAAAAAAAAAAAAAARARE//aAAgBAgEBPwFOjRT/AP/EABwQAAEDBQAAAAAAAAAAAAAAAAEAAhEQICExcf/aAAgBAQAGPwIwssLuI00iTNn/xAAcEAEBAAICAwAAAAAAAAAAAAABABEhMVFBYXH/2gAIAQEAAT8heGnPizK4/QcPsAgQ6ZFY9Fs7L3IQLi//2gAMAwEAAgADAAAAEM/v/wD/xAAZEQABBQAAAAAAAAAAAAAAAAAAARARIUH/2gAIAQMBAT8QAstGt//EABkRAAIDAQAAAAAAAAAAAAAAAAABECFBUf/aAAgBAgEBPxDiEtWZH//EABsQAQADAQEBAQAAAAAAAAAAAAEAESExYZGh/9oACAEBAAE/EDlaTKPfYqeAGrjYIvnOp4xW0JzWUWAjuMe5XsoEc2n7K90/YAKOT//Z","width":400,"height":400,"src":"/static/7399692f243327f85fff0a76e28b4a2b/2244e/sasjs-auth-login.jpg","srcSet":"/static/7399692f243327f85fff0a76e28b4a2b/2244e/sasjs-auth-login.jpg 1x,\n/static/7399692f243327f85fff0a76e28b4a2b/4fe8c/sasjs-auth-login.jpg 1.5x,\n/static/7399692f243327f85fff0a76e28b4a2b/14b42/sasjs-auth-login.jpg 2x"}}},"path":"/sasjs-auth-login","category":"SASjs","tags":["SASjs","SAS","Viya","SAS Admin"],"description":"The new sasjs auth login command lets you authenticate to SAS Viya with just a username and password - no registered OAuth client or secret required.","date":"2026/08/18"}}},"pageContext":{}}}