Named Credentials Developer Guide for OAuth
A named credential specifies the URL of a callout endpoint and its required authentication parameters in one definition. Using named credentials abstracts away the details of authentication protocols like OAuth and simplifies code for Apex developers. Though named credentials are represented by metadata, the standard Metadata API can’t fully expose the definition of a credential and render sensitive information like tokens in plain text.
A dedicated Connect API for named credentials closes this gap and provides Apex developers a means to create and manage credentials from your own code. This short guide walks through some relevant code samples to emulate as you use credentials against endpoints that require the OAuth protocol.
If you prefer to create and manage named credentials through the UI, see Create and Edit an OAuth External Credential and Create and Edit a Named Credential. These links contain information on the various parameters found in credentials, such as principal-level scopes versus credential-level scopes.