Class AuthorizationInfo

  • AuthorizationInfo checks if a user has granted authorization for required script scopes and provides an authorization URL to grant those permissions.

  • The AuthorizationInfo object allows you to control access to code sections requiring certain scopes and request authorization for subsequent executions.

  • AuthorizationInfo is returned byScriptApp.getAuthorizationInfo(authMode), withScriptApp.AuthMode.FULL being the generally recommended authorization mode.

  • Key methods of AuthorizationInfo includegetAuthorizationStatus(),getAuthorizationUrl(), andgetAuthorizedScopes().

AuthorizationInfo

An object that checks if the user has granted authorization for the required scopes of thescript. The object also provides an authorization URL for users to grant those permissions.

Some script executions can start without a user's consent to all required scopes used by thescript. The information in this object lets you control access to sections of code that requirecertain scopes and request authorization of those scopes for subsequent executions.

This object is returned byScriptApp.getAuthorizationInfo(authMode). In almostall cases, scripts should callScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL),since no other authorization mode requires that users grant authorization.

Methods

MethodReturn typeBrief description
getAuthorizationStatus()AuthorizationStatusGets a value that indicates whether the user needs to authorize this script to use one or moreservices (for example,ScriptApp.AuthorizationStatus.REQUIRED).
getAuthorizationUrl()String|nullGets the authorization URL that can be used to grant access to the script.
getAuthorizedScopes()String[]|nullGets a list of authorized scopes for the script.

Detailed documentation

getAuthorizationStatus()

Gets a value that indicates whether the user needs to authorize this script to use one or moreservices (for example,ScriptApp.AuthorizationStatus.REQUIRED).

// Log the authorization status (REQUIRED or NOT_REQUIRED).constauthInfo=ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);Logger.log(authInfo.getAuthorizationStatus());

Return

AuthorizationStatus — the authorization status


getAuthorizationUrl()

Gets the authorization URL that can be used to grant access to the script. This method returnsnull if no authorization is required. The page at the URL will close automatically ifit is accessed and the script does not require any authorization.

// Log the URL used to grant access to the script.constauthInfo=ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);Logger.log(authInfo.getAuthorizationUrl());

Return

String|null — a URL that can be used to authorize the script


getAuthorizedScopes()

Gets a list of authorized scopes for the script. If authorization information is requested fora specified list of scopes, returns the authorized scopes from the specified list.

// Logs which scopes in the specified list have been authorized for the script.constauthInfo=ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL,['https: //www.googleapis.com/auth/documents','https: //www.googleapis.com/auth/spreadsheets',]);Logger.log(authInfo.getAuthorizedScopes());

Return

String[]|null — The list of authorized scopes.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.