I have to provide OAuth access token to a JS SDK, The JS is uploaded in Static resource and referenced in visualforce
JS_SDK.accessToken = '{!my_access_token}';
From Named credential documentation, I understand that in apex we can construct custom headers by doing
req.setHeader('Authorization', 'access_token {!$Credential.OAuthToken}');
I have defined the named credential, authenticated and
checked: Allow Merge Fields in HTTP Header
& Allow Merge Fields in HTTP Body
fields.
Is there a way to refer the {!$Credential.OAuthToken}
in apex as a variable
and then refer in visualforce.
Does the merge field resolution only happen when the request is sent out ?