Step 3: Configure Your Search Experience
Step 1: Pass the Token to Search
Next, you’ll need to make sure that Search can accept the token you have minted. You’ll need to make the following changes to your repo, depending on if your Search experience is hosted with Core or Headless, or is living on a subdomain or an iFrame. You can refer to hitchhikers for more information between a subdomain here and iFraming here .
Option 1 (Recommended): Core or Headless
In provideCore, mint a token and pass it in place of the apiKey, and pass the visitor attribute from the Yext Auth object
import { provideCore } from '@yext/search-core';
const core = provideCore({
token: '<jwt>',
vistor: '<visitorId>', //OPT_IN FEATURE
//etc
})
Option 2: Subdomain
- In your global_config.json, set
useJWT
andinitializeManually
to true. - In the on_document_load partial, add the call for the runtime config with the
tokenHeader
attribute, and pass thevisitor
if you are using visitor analytics.
In order to add the on_document_load partial in Jambo, click Tools>Override Theme>script>on-document-load.js>Submit.
Since you are redirecting to this subdomain, you will need to store the token and visitor in local storage or in a url param, for the subdomain to use.
var token = this.localStorage?.myToken; // store the token in local storage
var token = this.window.hrefsomething; //store the token in a url param
var visitor = this.localStorage?.visitor; // store the token in local storage
var visitor = this.window.hrefsomething; //store the token in a url param
AnswersExperience.runtimeConfig.set('tokenHeader', token);
AnswersExperience.runtimeConfig.set('visitor', visitor);
AnswersExperience.init()
Option 3: JS Snippet (iFraming)
The following steps will be very similar to Using JWT with Search . In addition to those steps:
- In your global_config.json, set
initializeManually
anduseJWT
to true. - (Recommended) The domain for Search should be a subdomain of the parent domain, so that you can access things on the parent window from the iframe. This will likely make your life easier.
Call the following from the outer page
AnswersExperienceFrame.init({ "visitor": '<visitorId>', //OPT_IN FEATURE "tokenHeader": '<jwt>' }).
Step 2: Configure Search Bar
Next, you’ll need to configure the search bar on your website linking to your Search experience. There are two different search bar options which you can read more about here . The configuration of the search bar with Authorized Search changes in that you must pass in the token rather than API Key, in addition to now passing the visitor object if you are using visitor analytics (see the ‘Visitor Analytics’ step of this guide for more information).
Make the following changes when you initialize Search:
- Replace
apiKey
withtoken
. - Add
visitor
attribute (OPT_IN).
So, your search bar initialization will look something like the following:
ANSWERS.init({
token: '<jwt>'
visitor: '<visitorId>',
//etc
ANSWERS.addComponent(‘searchbar’, { .. });
});
Step 3: Edit Search Configuration
Finally, you’ll need to configure the verticals in your Search experience that you would like to use Authorized search. If using Yext Auth, you need to set the type to yext in the JSON config. You can do this by navigating to your Search experience, clicking Edit in Json on the left, and adding in this snippet of code for the vertical you intend to protect with Yext Auth permissions. Note that this is done on the vertical level.
If you are interested in using External Authorization as well, see the ‘Use External Authorization on Yext Users for Search’ step of this guide.
{
"verticals": {
"googleDrive": {
"entityTypes": ["googleDriveDocument"],
"authorization": {
"type": "yext"
}
},