ee.data.authenticateViaOauth
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Configure l'authentification côté client des appels d'API EE via la bibliothèque cliente des API Google pour JavaScript. La bibliothèque sera chargée automatiquement si elle ne l'est pas déjà sur la page. L'utilisateur sera invité à accorder à l'application identifiée par clientId l'accès à ses données EE s'il ne l'a pas déjà fait.
Cette méthode d'authentification ou une autre doit être appelée avant ee.initialize().
Notez que si l'utilisateur n'a pas encore accordé l'accès à l'application identifiée par l'ID client, une fenêtre de dialogue s'affiche par défaut pour l'inviter à accorder l'autorisation requise. Toutefois, ce pop-up peut être bloqué par le navigateur. Pour éviter cela, spécifiez le rappel opt_onImmediateFailed, puis affichez un bouton de connexion sur la page et appelez ee.data.authenticateViaPopup() à partir du gestionnaire d'événements de clic de ce bouton. Le navigateur ne bloque plus le pop-up, car il est désormais le résultat direct d'une action de l'utilisateur.
Le jeton d'authentification sera actualisé automatiquement lorsque cela sera possible. Vous pouvez partir du principe que tous les appels asynchrones seront envoyés avec les identifiants appropriés. Toutefois, pour les appels synchrones, vous devez rechercher un jeton d'authentification avec ee.data.getAuthToken() et appeler ee.data.refreshAuthToken() manuellement s'il n'y en a pas. L'opération d'actualisation du jeton est asynchrone et ne peut pas être effectuée en arrière-plan à la demande avant les appels synchrones.
Utilisation | Renvoie |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
Argument | Type | Détails |
---|
clientId | Chaîne | ID client OAuth de l'application ou valeur nulle pour désactiver les appels authentifiés. Vous pouvez l'obtenir dans la console Google Developers. Le projet doit avoir une origine JavaScript qui correspond au domaine sur lequel le script s'exécute. |
success | Fonction | Fonction à appeler si l'authentification a réussi. |
error | Fonction, facultatif | Fonction à appeler en cas d'échec de l'authentification, en transmettant le message d'erreur. Si l'authentification en mode immédiat (en arrière-plan) échoue et que opt_onImmediateFailed est spécifié, cette fonction est appelée à la place de opt_error. |
extraScopes | List<String>, facultatif | Champs d'application OAuth supplémentaires à demander. |
onImmediateFailed | Fonction, facultatif | Fonction à appeler en cas d'échec de l'authentification automatique en arrière-plan. La valeur par défaut est ee.data.authenticateViaPopup(), liée aux rappels transmis. |
suppressDefaultScopes | Booléen, facultatif | Si la valeur est "true", seuls les champs d'application spécifiés dans opt_extraScopes sont demandés. Les champs d'application par défaut ne sont pas demandés, sauf s'ils sont explicitement spécifiés dans opt_extraScopes. |
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/25 (UTC).
[null,null,["Dernière mise à jour le 2025/07/25 (UTC)."],[[["\u003cp\u003eEnables authenticated access to Earth Engine data using your Google account via the Google APIs Client Library for JavaScript.\u003c/p\u003e\n"],["\u003cp\u003eRequires initialization before using Earth Engine functionalities and might prompt users for permission to access their Earth Engine data.\u003c/p\u003e\n"],["\u003cp\u003eAutomatically refreshes authentication tokens for asynchronous calls, but synchronous calls may require manual token refresh using \u003ccode\u003eee.data.getAuthToken()\u003c/code\u003e and \u003ccode\u003eee.data.refreshAuthToken()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProvides options for handling authentication failures, including specifying custom error callbacks and displaying an in-page login button to avoid browser popup blockers.\u003c/p\u003e\n"],["\u003cp\u003eAllows customization of OAuth scopes and client ID for specific application requirements.\u003c/p\u003e\n"]]],[],null,["# ee.data.authenticateViaOauth\n\n\u003cbr /\u003e\n\nConfigures client-side authentication of EE API calls through the Google APIs Client Library for JavaScript. The library will be loaded automatically if it is not already loaded on the page. The user will be asked to grant the application identified by clientId access to their EE data if they have not done so previously.\n\n\u003cbr /\u003e\n\nThis or another authentication method should be called before ee.initialize().\n\nNote that if the user has not previously granted access to the application identified by the client ID, by default this will try to pop up a dialog window prompting the user to grant the required permission. However, this popup can be blocked by the browser. To avoid this, specify the opt_onImmediateFailed callback, and in it render an in-page login button, then call ee.data.authenticateViaPopup() from the click event handler of this button. This stops the browser from blocking the popup, as it is now the direct result of a user action.\n\nThe auth token will be refreshed automatically when possible. You can safely assume that all async calls will be sent with the appropriate credentials. For synchronous calls, however, you should check for an auth token with ee.data.getAuthToken() and call ee.data.refreshAuthToken() manually if there is none. The token refresh operation is asynchronous and cannot be performed behind-the-scenes on-demand prior to synchronous calls.\n\n| Usage | Returns |\n|------------------------------------------------------------------------------------------------------------------------------------|---------|\n| `ee.data.authenticateViaOauth(clientId, success, `*error* `, `*extraScopes* `, `*onImmediateFailed* `, `*suppressDefaultScopes*`)` | |\n\n| Argument | Type | Details |\n|-------------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `clientId` | String | The application's OAuth client ID, or null to disable authenticated calls. This can be obtained through the Google Developers Console. The project must have a JavaScript origin that corresponds to the domain where the script is running. |\n| `success` | Function | The function to call if authentication succeeded. |\n| `error` | Function, optional | The function to call if authentication failed, passed the error message. If authentication in immediate (behind-the-scenes) mode fails and opt_onImmediateFailed is specified, that function is called instead of opt_error. |\n| `extraScopes` | List\\\u003cString\\\u003e, optional | Extra OAuth scopes to request. |\n| `onImmediateFailed` | Function, optional | The function to call if automatic behind-the-scenes authentication fails. Defaults to ee.data.authenticateViaPopup(), bound to the passed callbacks. |\n| `suppressDefaultScopes` | Boolean, optional | When true, only scopes specified in opt_extraScopes are requested; the default scopes are not requested unless explicitly specified in opt_extraScopes. |"]]