Effettuare richieste API Adaptive Planning con credenziali Workday
Alcuni collegamenti in questo articolo rimandano alla Workday Community. Se non si dispone di un account Community, richiederne uno.
Gli utenti sincronizzati con Workday che accedono a Workday e utilizzano il
Adaptive Planning
La worklet può essere eseguita Adaptive Planning
API pubbliche Gli utenti devono creare un ISU specifico per effettuare queste richieste API. Questi utenti devono fornire un token nel file credentials
elemento di Adaptive Planning
Richieste API anziché nome utente e password. È possibile memorizzare nella cache questo token e utilizzarlo fino alla scadenza. Dopo la scadenza, è necessario ottenere un nuovo token.
Prerequisiti
Prerequisiti
Dominio Workday e gruppi di sicurezza
- Verificare che gli utenti ISU che necessitano dell'accesso all'API facciano parte del dominio di sicurezzaSet Up: Adaptive Planning API Access.
Attività di configurazione di Workday
- Verificare che le attivitàSingle Sign-Onsiano abilitate nella schedaUser Sign-Ondel fileAdaptive Planningscheda
- Verificare che l'attivitàdi configurazione dell'API pubblicasia abilitata nella schedaAPI pubblicadel fileAdaptive Planningscheda
- Verificare che l'attività di configurazione di un utente del sistema di integrazione (ISU) abbia creato un ISU specifico per effettuare richieste API Workday Adaptive Planning e l'abbia mappato a unAdaptive Planningaccount utente
Adaptive Planning
Amministratore utente- Verificare di visualizzare l'ISU che inizia conPublicAPIISU_nell'elenco degli utenti in Amministrazione > Utenti.
- Verificare che l'utente disponga del livello di accesso necessario per le API che desidera eseguire. I nuovi ISU non ricevono l'accesso a livello per impostazione predefinita.
Procedura
Procedura
- Ottenere un certificato ed estrarre la chiave pubblica.
- Registrare un client API in Workday con tale certificato.
- Generare un token JWT, Retrieve Workday access_token e Retrieve AdaptiveAPIAccessToken.
- Utilizzare AdaptiveAPIAccessToken in unAdaptive PlanningRichiesta API
Ottenere un certificato ed estrarre la chiave pubblica
È possibile creare un certificato autonomamente o acquistarlo da un'autorità di certificazione nota. Per i dettagli sui parametri necessari per il certificato X.509 in Workday, consultare Concetto: Certificati X.509 in Workday.
- Estrarre la chiave pubblica dal certificato per caricarla nel sistema.
- Conservare la chiave privata per l'utilizzo nell'applicazione chiamante.
- Incollare il certificato nel sistema durante la registrazione del token di trasporto JWT. Fare riferimento alla chiave privata nello script.
Consultare OAuth con JWT (token Web JSON) e Access External Endpoints.
Registrare un client API Workday
- Registrare un client API conClient Grant Type: Jwt Bearer Grantin Workday. Per ulteriori informazioni, consultare Registrare un client API .
- Copiare la chiave pubblica derivata per il certificato nellapagina Certificato x.509nella pagina Register API Client di Workday.
- PerAmbito (area funzionale)selezionare.Adaptive Planning
- Al termine della registrazione del client API, copiare i campi risultanti nella parte inferiore della pagina in un file di testo da utilizzare in seguito.
- Endpoint API REST di Workday
- Endpoint token
- Endpoint di autorizzazione
Generare token JWT, Recuperare access_token di Workday e Recuperare AdaptiveAPIAccessToken
- Utilizzare la chiave privata e generare il token JWT eseguendo lo pseudocodice elencato di seguito.
- Per recuperare un token di accesso Workday, creare unPOSTrichiesta all'endpoint token, superandogrant_typeeassertion. Utilizzare l'endpoint token copiato dopo la registrazione del client API nel sistema. Esempio di endpoint token:https://{host or gateway}/ccx/oauth2/{tenant}/tokenEsempioCURLrichiesta all'endpoint tokencurl --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}}'
- Recuperare AdaptiveAPIAccessToken chiamando l'endpoint Workday utilizzando il token di accesso Workday. Utilizzare il precedenteaccess_tokencome token Bearer inAuthintestazione per questoGET.Esempio di token di accesso:https://{host or gateway}/ccx/api/planning/v1/{tenant}/adaptiveAPIAccessTokenEsempioCURLrichiesta per AdaptiveAPIAccessToken:curl --request GET 'https://{host or gateway}/ccx/api/planning/v1/{tenant}/adaptiveAPIAccessToken' \ --header 'Authorization: Bearer {{the prior access_token value}}' \ --data-raw ''
- ChiamareAdaptive PlanningAPI che utilizza AdaptiveAPIAccessToken nell'elemento credenziali dell'XML in un HTTPPOST. Esempio: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
Applicazione Java di esempio per la generazione di un token JWT
Questa applicazione Java di esempio genera un token 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 ""; } }
Esempio di applicazione C# per la generazione di un token JWT
Questa applicazione C# di esempio genera un token JWT che sostituisce il nome utente e la password nell'elemento credenziali di un'istanza
Adaptive Planning
Richiesta APIQuesto codice di esempio richiede una pagina NuGet. Pacchetto NuGet obbligatorio:
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);
Utilizzare AdaptiveAPIAccessToken in un Adaptive Planning Richiesta API
Adaptive Planning
Richiesta APIDopo aver configurato il sistema per
Adaptive Planning
accesso API pubblico, l'elemento credenziali di Adaptive Planning
Le richieste API utilizzano AdaptiveAPIAccessToken invece di nome utente e password. L'autenticazione di base con nome utente e password non funziona. Per ulteriori informazioni, consultare API REST e Metodi API di Adaptive Planning.Esempio AdaptiveAPIAccessToken in an Adaptive Planning Richiesta API
Adaptive Planning
Richiesta 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>