Faire des demandes d'API Adaptive Planning avec des données d'identification Workday
Certains liens figurant dans cet article redirigent vers Workday Community. Si vous n'avez pas de compte Community, demandez-en un.
Utilisateurs synchronisés avec Workday qui se connectent à Workday et utilisent le
Adaptive Planning
Worklet peut exécuter Adaptive Planning
API publiques. Les utilisateurs doivent créer un ISU spécialement pour effectuer ces demandes d’API. Ces utilisateurs doivent fournir un jeton dans le champ credentials
élément de Adaptive Planning
Des demandes d’API au lieu d’un nom d’utilisateur et d’un mot de passe. Vous pouvez mettre ce jeton en cache et l’utiliser jusqu’à son expiration. Après son expiration, vous devez obtenir un nouveau jeton.
Conditions préalables
Conditions préalables
Domaine Workday et groupes de sécurité
- Vérifiez que les utilisateurs ISU qui ont besoin d’accéder à l’API font partie du domaine de sécuritéSet Up: Adaptive Planning API Access.
Tâches de configuration de Workday
- Vérifiez que les tâchesd'authentification uniquesont activées dans l'ongletAuthentification des utilisateursdeAdaptive Planningun onglet.
- Assurez-vous que la tâchede configuration de l'API publiqueest activée dans l'ongletde l'API publique,Adaptive Planningun onglet.
- Vérifiez qu'une tâche de configuration utilisateur du système d'intégration (ISU) a créé une ISU spécialement pour faire des demandes d'API Workday Adaptive Planning et l'a mappée à une valeurAdaptive Planningcompte d'utilisateur.
Adaptive Planning
Administration des utilisateurs- Vérifiez que l'utilisateur de système d'intégration commence parPublicAPIISU_dans la liste des utilisateurs sous Administration > Utilisateurs.
- Vérifiez que cet utilisateur dispose du niveau d’accès requis pour les API qu’il souhaite exécuter. Par défaut, les nouveaux utilisateurs ISU ne reçoivent pas l’accès au niveau.
Étapes
Étapes
- Obtenez un certificat et extrayez votre clé publique.
- Enregistrez un client API dans Workday avec ce certificat.
- Générez un jeton JWT, récupérez Access_token de Workday et récupérez AdaptiveAPIAccessToken.
- Utilisez AdaptiveAPIAccessToken dans uneAdaptive PlanningDemande d’API.
Obtenir un certificat et extraire votre clé publique
Vous pouvez créer un certificat vous-même ou acheter un certificat auprès d’une entité de délivrance de certificats reconnue. Pour en savoir plus sur les paramètres nécessaires pour votre certificat X.509 dans Workday, voir Concept: X.509 Certificates in Workday.
- Extrayez la clé publique de votre certificat pour le téléverser dans Workday.
- Conservez votre clé privée pour pouvoir l'utiliser dans votre application d'appel.
- Collez le certificat dans Workday lors de l'enregistrement de votre jeton de titulaire JWT. Référence de votre clé privée dans votre script.
Enregistrer un client API Workday
- Enregistrez un client API avecle type d’octroi de client : JWT Porteur Grantdans Workday. Voir Enregistrer un client API pour plus d’informations.
- Copiez la clé publique dérivée de votre certificat dans lecertificat x.509de la page Register API Client de Workday.
- Pourle champ Scope (domaine fonctionnel),sélectionnez.Adaptive Planning
- Quand vous avez terminé l’enregistrement du client API, copiez les champs résultants au bas de la page dans un fichier texte pour une utilisation ultérieure.
- Point de terminaison de l’API REST de Workday
- Point de terminaison du jeton
- Point de terminaison d’autorisation
Générer un jeton JWT, récupérer Workday Access_token et récupérer AdaptiveAPIAccessToken
- Utilisez votre clé privée et générez le jeton JWT en exécutant le pseudo-code répertorié ci-dessous.
- Pour récupérer un jeton d’accès Workday, faites unePOSTdemande au point de terminaison du jeton, en faisant passergrant_typeEtassertion. Utilisez le point de terminaison de jeton copié après l'enregistrement de votre client API dans Workday. Exemple de point de terminaison de jeton :https://{host or gateway}/ccx/oauth2/{tenant}/tokenExempleCURLdemande au point de terminaison du jetoncurl --request POST 'https://{host or gateway}/ccx/oauth2/{tenant}/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer' \ --data-urlencode 'assertion={{the jwt assertion from your certificate}}'
- Récupérez AdaptiveAPIAccessToken en appeler le point de terminaison Workday à l’aide du jeton d’accès Workday. Utiliser la valeur précédenteaccess_tokencomme jeton Porteur dansAuthen-tête associéGET.Exemple de jeton d’accès :https://{host or gateway}/ccx/api/planning/v1/{tenant}/adaptiveAPIAccessTokenExempleCURLDemande pour AdaptiveAPIAccessToken :curl --request GET 'https://{host or gateway}/ccx/api/planning/v1/{tenant}/adaptiveAPIAccessToken' \ --header 'Authorization: Bearer {{the prior access_token value}}' \ --data-raw ''
- Appelez leAdaptive PlanningAPI utilisant AdaptiveAPIAccessToken dans l’élément de créances du XML dans un HTTPPOST. Exemple :curl -H "Content-Type: text/xml" -d '<?xml version='1.0' encoding='UTF-8'?><call method="exportLevels" callerName="a string that identifies your client application"><credentials token="ID eyJhbDci0iJSUzUxMiIsUmtpZCI6IdvcmtkYXlfa2V5In0.eyJpc3KiOiJXb3JrZGFZIiwiYXV0aF90aW1lIjoxNTczMTY3NjU2LBjzeXnfynnJd.bztQzBmHeTj1amnHA-r96TdrJK0MXMghUFF1KyjxqIq6ruHU63dJp3JAJn3Eche7SEcoZBVGX4wJgna106pmCqgrrVWMf13Hg_sb_szabal2XN1KEEk1qh8z1IDlbt6qJIL_xyW3J2nNSs5ima3vJUYU5sRQXwXst0GuFWXpy464GyB4oKcscrg28X3dnPO_ytdohMKHsWkqyHQKXFQwoQezFaGy10sp4RRUj0lpOZX8C9oBHDYA58IXxGkqKLJVNPvDND6rGY5fTHQ-yxpe1nz-WqB0boiq9a-dv8b3EBzbelxj2fCPdMbng6kzygDcA2at_7BNQiyzfIovS5AG"/><include versionID="3" inaccessibleValues="false"/><sheet id="3" /></call>' -X POST https://api.adaptiveplanning.com/api/v23
Exemple d’application Java pour générer un jeton JWT
Cet exemple d’application Java génère un jeton JWT.
//********************************************************************** // // File: TestPublicAPISample.java // // Copyright 2004-2019 Workday Adaptive Planning. // All Rights Reserved. // // This work contains trade secrets and confidential material of // Workday Adaptive Planning and its use or disclosure in whole or in part // without the express written permission of Workday Adaptive Planning is prohibited. // //********************************************************************** import java.io.FileInputStream; import java.security.KeyStore; import java.security.PrivateKey; import java.security.Signature; import java.text.MessageFormat; //import java.util.Base64; import org.apache.commons.codec.binary.Base64; public class AccessAdaptiveAPI { public static void main(String args[]) { String jwtKeyStoreFileString = "/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/jre/lib/security/JWTkeystore.jks"; String clientIDString = "BlywNDM1NmMtZTk2Mi00NTZiTWEyZjktZWM1NGJiOGQ3Yjca"; String userIdString = "PublicAPIISU_Test"; System.out.println(GetAccessToken(clientIDString,userIdString,jwtKeyStoreFileString)); } public void callAPI() { } public String getAdaptiveAPIToken() { return ""; } public String getJWTToken(String privateKey, String username) { return ""; } public void callWorkdayAPI() { } public static String GetAccessToken(String clientId, String userId, String jwtKeyStore) { String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"; String claimTemplate = "'{'\"iss\": \"{0}\", \"sub\": \"{1}\", \"aud\": \"{2}\", \"exp\": \"{3}\"'}'"; try { StringBuffer token = new StringBuffer(); //Encode the JWT Header and add it to our string to sign token.append(Base64.encodeBase64URLSafeString(header.getBytes("UTF-8"))); //Separate with a period token.append("."); //Create the JWT Claims Object String[] claimArray = new String[4]; //iss claimArray[0] = clientId; //sub claimArray[1] = userId; //aud claimArray[2] = "wd"; //exp claimArray[3] = Long.toString( ( System.currentTimeMillis()/1000 ) + 300); MessageFormat claims; claims = new MessageFormat(claimTemplate); String payload = claims.format(claimArray); //Add the encoded claims object token.append(Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8"))); //token.append(Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8"))); //Load the private key from a keystore KeyStore keystore = KeyStore.getInstance("JKS"); keystore.load(new FileInputStream(jwtKeyStore), "Workday123!".toCharArray()); PrivateKey privateKey = (PrivateKey) keystore.getKey("Workday", "Workday123!".toCharArray()); //Sign the JWT Header + "." + JWT Claims Object Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(privateKey); signature.update(token.toString().getBytes("UTF-8")); String signedPayload = Base64.encodeBase64URLSafeString(signature.sign()); //Separate with a period token.append("."); //Add the encoded signature token.append(signedPayload); return token.toString(); //System.out.println(token.toString()); } catch (Exception e) { e.printStackTrace(); } return ""; } }
Exemple d’application C# pour générer un jeton JWT
Cet exemple d’application C# génère un jeton JWT qui remplace le nom d’utilisateur et le mot de passe dans l’élément d’identification d’un
Adaptive Planning
Demande d’API.Cet exemple de code nécessite une page CloudGet. EnsembleNuGet requis :
System.IdentityModel.Tokens.Jwt
var clientId = "BlywNDM1NmMtZTk2Mi00NTZiTWEyZjktZWM1NGJiOGQ3Yjca";//Client ID from workday API Client var isu = "PublicAPIISU_Test"; //the ISU var timeout = (DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() / 1000 + 300).ToString(CultureInfo.InvariantCulture); var environment = "wd"; var pfxFilePath = @"C:\temp\JWTkeystore2.pfx"; var pfxPassword = "Workday123!"; var payload = new JwtPayload { {"iss", clientId}, {"sub", isu}, {"aud", environment}, {"exp", timeout }, }; var signingCredentials = new X509SigningCredentials(new X509Certificate2(pfxFilePath, pfxPassword), SecurityAlgorithms.RsaSha256); // the matching PKCS #12 file with private key var jwtHeader = new JwtHeader(signingCredentials); var secToken = new JwtSecurityToken(jwtHeader, payload); var handler = new JwtSecurityTokenHandler(); var tokenToWorkday = handler.WriteToken(secToken); Console.WriteLine(tokenToWorkday);
Utilisez AdaptiveAPIAccessToken dans une Adaptive Planning Demande d'API
Adaptive Planning
Demande d'APIUne fois que vous avez configuré Workday pour
Adaptive Planning
accès API public, l’élément lié aux données d’identification de Adaptive Planning
Les demandes d'API utilisent AdaptiveAPIAccessToken au lieu d'un nom d'utilisateur et d'un mot de passe. L'authentification de base avec nom d'utilisateur et mot de passe ne fonctionne pas. Voir API REST et méthodes API
Adaptive Planning pour plus d'informations.Exemple AdaptiveAPIAccessToken dans une Adaptive Planning Demande d'API
Adaptive Planning
Demande d'API<?xml version='1.0' encoding='UTF-8'?> <call method="exportLevels" callerName="a string that identifies your client application"> <credentials token="ID eyJhbDci0iJSUzUxMiIsUmtpZCI6IdvcmtkYXlfa2V5In0.eyJpc3KiOiJXb3JrZGFZIiwiYXV0aF90aW1lIjoxNTczMTY3NjU2LBjzeXnfynnJd.bztQzBmHeTj1amnHA-r96TdrJK0MXMghUFF1KyjxqIq6ruHU63dJp3JAJn3Eche7SEcoZBVGX4wJgna106pmCqgrrVWMf13Hg_sb_szabal2XN1KEEk1qh8z1IDlbt6qJIL_xyW3J2nNSs5ima3vJUYU5sRQXwXst0GuFWXpy464GyB4oKcscrg28X3dnPO_ytdohMKHsWkqyHQKXFQwoQezFaGy10sp4RRUj0lpOZX8C9oBHDYA58IXxGkqKLJVNPvDND6rGY5fTHQ-yxpe1nz-WqB0boiq9a-dv8b3EBzbelxj2fCPdMbng6kzygDcA2at_7BNQiyzfIovS5AG"/> <include versionID="3" inaccessibleValues="false"/> <sheet id="3" /> </call>