MINHAZ KAZI: Welcome to DataVis DevTalk.
I'm your host, Minhaz Kazi, developer advocate
for Data Studio.
In this episode for DataVis DevTalk,
you'll learn how authentication flow works for community
connectors and how you can authorize your users
to use external services.
Let's get started.
[MUSIC PLAYING]
When a user tries to use a connector for the first time,
Data Studio triggers the Connector Authorization flow.
Connector Authorization is a 2-step process.
First, the Google OAuth2 flow is triggered
to allow Data Studio to execute the connector.
This flow includes all the necessary scopes
required by the connector.
We talked about the OAuth scopes in our episode about Manifest.
In the first step, the user will review the scopes
and complete the authorization process.
In the second step, Data Studio triggers additional OAuth flow
if the connector needs to reach any external service.
This second step is initiated by Data Studio
by making the getAuthType call to the connector.
At this point, there are several use cases
when you will not need any additional credentials
from the user.
The first use case is if you're not connecting
to any external service.
For example, if you're connecting to the Google Fit
API, the OAuth scope will be a part of the Google OAuth2 flow
and no further authorization is required.
The second use case is if you're connecting
to an external service that does not require the user
to authenticate.
For example, if you're fetching data from the npm Download
Count public API, it does not require
any kind of authentication.
And the last use case is if you're
accessing external services using a private secret,
like a service account credential or a token.
For example, the Stack Overflow API requires an API key.
You can generate your own API key,
store it in your Script Properties,
and use the stored API key every API call you make.
In these use cases, you will return the Auth type NONE
for the getAuthType response.
Data Studio will then proceed with the connector
configuration.
However, if you require a user's credentials
to authenticate to external services,
you should return the Auth type required
by your specific external service.
Your options for authentication include
API key, username and password, username and token, and OAuth2.
For a complete list of authentication types,
check out the reference link for the getAuthType
in the description below.
If the service you connecting to requires the user
to provide their credentials via an OAuth2 process,
you should use the OAuth2 for Apps Script library.
This will make the implementation a lot easier.
The library will also be useful if you're
using service accounts with an OAuth2-based service.
In this type of authentication, Data Studio
will open a new window and redirect the user
to the service provider's login screen.
Once the user logs in and provides
the necessary permissions to the connector,
the user will be able to resume the connector configuration
in Data Studio.
If you're using the OAuth2 for Apps Script library
in your connector code, you'll be
able to access the user token through the library.
An advanced tip.
If your connector is connecting to your own service,
you have the flexibility to set up
any kind of custom authentication
and authorization flow at your end using the OAuth2 method.
If your connector requires a different authentication
than OAuth2, like API key or username-password,
Data Studio will render the required interface
so the user can provide the credentials in Data Studio.
You should use the Apps Script Property service
and store these credentials in the User Property Store
and fetch them when required.
You'll need to write a few additional functions
in your code if you're using any Auth type other than NONE.
These functions will allow Data Studio
to verify the credentials and reset them when required.
Details about these functions, how to implement them,
along with code examples are available in the Authentication
Guide linked in the description below.
To learn more, check out the links in the description below,
and don't forget to subscribe to the GCP channel
for more great content on Data Studio.
Thanks for watching.
And until next time, keep building awesome dashboards.
[MUSIC PLAYING]