---
schema_version: "1"
id: 92bbbf795ca07d796b9f689cb1dd96f8cffa8231b4d47b68e0f8db2242e28d3a
title: Get an Authentication URL
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/connectapi_examples_get_an_authentication_url.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/connectapi_examples_get_an_authentication_url.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 808468faba4b3913f562c4e327e1c90ec50712c806de2e423cf1b61ca7e0f508
description: Call a method to get an authentication URL.
---
# Get an Authentication URL

Call a method to get an authentication URL.

Call [getOAuthCredentialAuthUrl(requestBody)](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_ConnectAPI_NamedCredentials_static_methods.htm#apex_ConnectAPI_NamedCredentials_getOAuthCredentialAuthUrl_1) to retrieve the URL that a user must visit to begin an authentication flow, ultimately returning authentication tokens to Salesforce. Accepts input parameters representing a specific external credential and, optionally, a named principal. Use this method as part of building a customized or branded user interface to help users initiate authentication.

ConnectApi.OAuthCredentialAuthUrlInput input = new ConnectApi.OAuthCredentialAuthUrlInput();

input.externalCredential = 'MyExternalCredentialDeveloperName';
input.principalType = ConnectApi.CredentialPrincipalType.PerUserPrincipal;
input.principalName = 'MyPrincipal'; // Only required when principalType = NamedPrincipal

ConnectApi.OAuthCredentialAuthUrl output = ConnectApi.NamedCredentials.getOAuthCredentialAuthUrl(input);

String authenticationUrl = output.authenticationUrl; // Redirect users to this URL to authenticate in the browser

#### See Also

- [_Apex Reference Guide_: NamedCredentials Methods](https://developer.salesforce.com/docs/atlas.en-us.264.0.apexref.meta/apexref/apex_ConnectAPI_NamedCredentials_static_methods.htm "Apex Reference Guide: NamedCredentials Methods - HTML (New Window)")