Power BI : se connecter aux API en mode REST avec un Service Principal Azure AD

Dans cet article, nous allons voir comment se connecter aux API Power BI en mode REST en utilisant un service princial (SP). Pour rappel, nous avons déjà utilisé la méthode du SP avec Azure Data Factory dans un de mes précédents articles =>  ICI. L’idée maintenant c’est d’utiliser cette méthode avec n’importe quelles technologies et langages avec du REST.

L’utilisation des SP est très pratique, car ainsi nous n’avons plus besoin d’avoir un compte utilisateur AD à gérer (comme avec les modes UserOwnsData ou AppOwnsData), et en plus cela fait aussi économiser une licence Power BI Pro, il n’y a pas de petites économies Smile

YoungCandidCrossbill-size_restricted

Commencez par créer un SP dans Azure AD et configurer Power BI pour activer l’authentification via service principal, la doc MS explique tout ça : https://docs.microsoft.com/fr-fr/power-bi/developer/embedded/embed-service-principal

Puis récupérez l’application ID et le tenant ID, vous pouvez notamment passer par le portail Azure dans les paramètres de votre SP (le menu s’appelle App registrations) :

MbcpAm3hXR

Et créez aussi un secret pour votre SP, il faut le sauvegarder quelque part car il est accessible que lors de sa création :

NZumIlukgX

Comme le SP va se connecter directement à Power BI, n’oubliez pas de lui donner des droits sur les Workspaces auxquels il aura accès. Attention, cela ne fonctionne qu’avec les Workspace V2 !

Pour se connecter aux API, il va d’abord falloir récupérer un token d’authentification en envoyant une requête POST au service d’’authentification Microsoft “login.microsoftonline.com” en passant les bonnes informations de connexion en body. Le body devra avoir le format suivant et contenir votre application ID et son secret :

{
	"Grant_type": "client_credentials",
	"Resource": "https://analysis.windows.net/powerbi/api",
	"Client_id": "<Application ID>",
	"Client_secret": "<Application Secret>",
	"Scope": "https://analysis.windows.net/powerbi/api/.default"
}

L’url à appeler devra aussi contenir le tenant id de votre AD : https://login.microsoftonline.com/<tenantid>/oauth2/token

En réponse de l’appel, vous pourrez récupérer un token :

{
    "token_type":  "Bearer",
    "expires_in":  "3599",
    "ext_expires_in":  "3599",
    "expires_on":  "1594665662",
    "not_before":  "1594661762",
    "resource":  "https://analysis.windows.net/powerbi/api",
    "access_token":  "<ICI>"
}

Vous pourrez alors l’utiliser dans tous vos appels aux API Power BI en le mettant dans le paramètre authorization du header :

{
    "Authorization":  "Bearer  <ICI>",
    "Content-Type":  "application/json"
}

Et c’est gagné !

Attention, le token expire au bout d’un certain temps, il faut prévoir de le regénérer si besoin.

Pour finir, voici un exemple complet en PowerShell qui liste au final les Workspaces auxquels le SP à accès :

#Specify SP informations
$tenantid = '<Tenant ID>'
$appID = '<Application ID>'
$appSecret = '<Application Secret>'


#Get token
$TokenArgs = @{
    Grant_type = 'client_credentials'
    Resource   = 'https://analysis.windows.net/powerbi/api'
    Client_id  = $appID
    Client_secret = $appSecret
    Scope = "https://analysis.windows.net/powerbi/api/.default"
}
$out = Invoke-RestMethod -Uri https://login.microsoftonline.com/$tenantid/oauth2/token -Body $TokenArgs -Method POST
 
#Save token
$tokenaccess = $out.access_token

#Get group API test
$header = @{
    'Content-Type'='application/json'
    'Authorization'= "Bearer  $tokenaccess" 
}
$uri = "https://api.powerbi.com/v1.0/myorg/groups"
$outrequest = Invoke-RestMethod -Method Get -Uri $uri -Headers $header

#Show results
$outrequest.value 

Il vous reste plus qu’à parcourir la documentation des API Power BI pour trouver la ou les bonnes méthodes à appeler en fonction de vos besoins : https://docs.microsoft.com/en-us/rest/api/power-bi/

FIN !

FADATA

Fabien Adato est Customer Engineer Data et AI chez Microsoft. Après avoir intégré la société CGI Business Consulting où il rejoint une équipe dédiée à la Business Intelligence, il fait ses premières armes sur la solution Microsoft SQL Server. Pendant plus de 4 ans, il acquiert des compétences techniques et fonctionnelles sur toute la chaîne de valeur de la BI (ETL, Base de Données, Cube Olap et Rapport). Il a pu se spécialiser également sur de nouvelles technologies de la Data et notamment Hadoop, Pig et Hive, ainsi que des technologies self-service BI, le No-SQL comme la base de données MongoDB et le moteur d’indexation ElasticSearch. Il entre chez AZEO en 2014 puis Avanade en 2021 puis Microsoft en 2021 pour y assurer le poste de CE DATA / AI, autour des technologies Microsoft SQL Server, Power BI et Azure Data.

44 thoughts on “Power BI : se connecter aux API en mode REST avec un Service Principal Azure AD

  1. Thank you very much for kindly sharing this interesting article, hope to read more like this one.
    Regards Military Barrier – Chinese Wholesaler & Exporter
    https://www.militarybarrier.com
    military barrier for sale 

    https://www.militarybarrier.com/military-defense-barrier/
    defensive barrier

    https://www.militarybarrier.com/razor-barbed-wire/
    razor barbed wire

    https://www.militarybarrier.com/blast-walls-can-save-a-lot-of-manpower-and-time-when-preventing-floods-blastwall-savemanpower-savetime-preventflood/
    blast wall

    https://www.militarybarrier.com/joesco-razor-wire-rapid-deployment-vehicle-an-advanced-mobile-solution-for-rapid-deployment-of-security-fencing-and-barriers/
    rapid deployment barrier

    https://www.militarybarrier.com/joesco-barrier-got-ce-certificate/
    ce certification barbed wire products

    https://www.militarybarrier.com/the-gabion-blast-wall-is-a-new-type-of-blast-wall-that-features-high-strength-impact-resistance-and-explosion-resistance/blast proof barrier

    https://www.gabion.biz/
    landscape gabion wall,garden gabion,trapezoidal gabion wall

    https://www.gabion.biz/products/gabion-mats-gabion-reno-mattresses/
    Gabion Mats, Gabion Reno Mattresses

    https://www.gabion.biz/products/gabion-baskets-stone-box/
    Gabion Baskets

    https://www.gabion.biz/products/gabion-wall-welded-gabion-weld-mesh-gabion-rock-box/
    Gabion Wall, Welded Gabion box, Weld Mesh Gabion, Rock Box

    http://www.joesco.cn/
    military barriers wholesale,military barriers manufacturer

    https://medium.com/@joesco189/military-barriers-innovative-solutions-evolved-from-gabion-baskets-ddea6145276e military defense barriers
    https://www.youtube.com/channel/UCxHwYpwbuEE3rz00yofOO9A military barriers
    https://www.tiktok.com/@joesco_barrier cheap military barriers,blast wall
    https://www.facebook.com/profile.php?id=100009622980334 military bastion
    https://www.blogger.com/blog/posts/6449305831592860858 military barriers
    https://www.tumblr.com/blog/joesco-military-defense-barrier blast wall
    https://www.vingle.net/joesco189 cheap military barriers

  2. Phantom Wallet Extension stands out when compared to traditional wallets in several aspects. Unlike hardware wallets that require physical devices, Phantom offers the convenience of browser integration. It ensures quick access to your funds without compromising security.
    Phantom Wallet Extension

  3. MetaMask Chrome Extension is a popular browser extension for Chrome that enables users to interact with Ethereum blockchain. With MetaMask, users can securely manage their Ethereum accounts.

    MetaMask Chrome Extension is a widely used cryptocurrency wallet and decentralized application (dApp). With MetaMask, users can securely store, manage, and interact with various cryptocurrencies.

    MetaMask Extension is a popular browser extension that serves as a cryptocurrency wallet and gateway to the decentralized web. Available as an extension for browsers like Chrome.

    MetaMask Extension With its user-friendly interface and robust security features, MetaMask has become a go-to tool for individuals looking to engage with cryptocurrencies and explore the possibilities of the decentralized web.

    1. Metamask Login Chrome is a Chrome involves installing the extension, creating or importing a wallet, and securely accessing decentralized applications. Users manage cryptocurrencies, interact with dApps, and ensure private key security.

      MetaMask Sign in To sign in to MetaMask, open the extension, enter your password or use biometrics, and gain access to your Ethereum-based assets, decentralized applications, and secure wallet functionality within your browser.

      Metamask Wallet Extension is a browser extension wallet for managing cryptocurrencies and interacting with decentralized applications (DApps) on the Ethereum blockchain. It offers a secure and convenient way to store and transact with digital assets.

      Crypto.com Login Issues Users experiencing Crypto.com login issues may encounter problems accessing their accounts, possibly due to technical glitches, forgotten passwords, or security measures. Troubleshooting may involve password resets or contacting customer support.

  4. Metamask Login Chrome is a Chrome involves installing the extension, creating or importing a wallet, and securely accessing decentralized applications. Users manage cryptocurrencies, interact with dApps, and ensure private key security.

    MetaMask Sign in To sign in to MetaMask, open the extension, enter your password or use biometrics, and gain access to your Ethereum-based assets, decentralized applications, and secure wallet functionality within your browser.

    Metamask Wallet Extension is a browser extension wallet for managing cryptocurrencies and interacting with decentralized applications (DApps) on the Ethereum blockchain. It offers a secure and convenient way to store and transact with digital assets.

    Crypto.com Login Issues Users experiencing Crypto.com login issues may encounter problems accessing their accounts, possibly due to technical glitches, forgotten passwords, or security measures. Troubleshooting may involve password resets or contacting customer support.

  5. Metamask Wallet is a popular cryptocurrency wallet and browser extension that allows users to manage their Ethereum-based assets and interact with decentralized applications (DApps) on the Ethereum blockchain.
    Metamask Wallet extension is a browser extension that facilitates seamless interaction with blockchain-based applications and manages cryptocurrency assets. Primarily designed for the Ethereum blockchain, this extension enables users to securely store, send, and receive Ethereum and ERC-20 tokens.
    Venguard Login refers to a specific platform, website, or service introduced after January 2022, I recommend checking the official website or contacting customer support for accurate and up-to-date information on how to log in.
    Venguard 401k login you should visit the official Vanguard website to access your 401(k) account. Navigate to the login or account access section on the official website, and provide your credentials to log in securely.

  6. LOBSTR Wallet offers a seamless and user-friendly platform for managing your cryptocurrency transactions. Whether you’re a seasoned crypto enthusiast or just starting your journey.

    LOBSTR Login provides a user-friendly gateway to your crypto universe. Whether you’re a seasoned crypto enthusiast or just starting your journey, LOBSTR offers a simple and secure login.

  7. CLV Finance is a pioneering project focused on cross-chain decentralized finance (DeFi) interoperability. Recognizing the need for seamless communication between different blockchain networks, CLV Finance aims to bridge the gap, enabling users to access and utilize decentralized financial services across multiple platforms.

  8. Slingshot Finance introduces a Web3 approach to crypto swapping, revolutionizing decentralized exchanges. This platform facilitates seamless and secure token swaps while harnessing the power of blockchain technology.

  9. Saitapro offers innovative solutions for businesses, specializing in software development, IT consulting, and digital marketing services. Our experienced team is dedicated to delivering tailored strategies and cutting-edge technology to enhance your company’s success. Trust Saitapro for reliable, scalable, and efficient solutions that drive growth in today’s dynamic business landscape.

    Saitapro | Saitamask

  10. Curve Finance is a decentralized finance (DeFi) protocol optimizing stablecoin trading with low slippage. It enables efficient liquidity pools for stablecoin swaps on the Ethereum blockchain.

  11. Already a crypto.com login user? Continue as crypto.com sign in issues User. Or. Email. Password. Log In Forget password? Don’t have an account? Sign Up Now. Sign up for a Crypto.com NFT account · Connect your verified crypto.com sign in issues· Submit an application to become a creator · Once approved, start minting your Log In to crypto.com sign in issues Price Already a Crypto.com App user? Log In Forget password? Don’t have an account?Sign Up Now. Crypto.com App. Trade crypto on the go. Anytime, anywhere. Log In · Sign Up. Company. Trade. Services.

  12. Those users who already have their MetaMask login credentials would agree with me on this point that MetaMask is a true example of an ETH-based crypto wallet. To give you a better idea about the same, the following segment will walk you through its features.

  13. Phantom is a self-custodial and Web 3.0 wallet created for the Solana (SOL) blockchain. The wallet provides many services that complement the key wallet functionality, like NFT marketplace, token swap, multi-chain support, and more. If you are looking for an intuitive user interface, top-notch safety features, and comprehensive support, Phantom Wallet Extension is a great option.

    Phantom Extension | Phantom Extension

  14. Phantom Wallet Extension is a decentralized cryptocurrency wallet explicitly made for the Solana blockchain. The extension provides a secure and easy user experience by integrating directly with web browsers, enabling users to manage their Solana-based files easily. Phantom acts as a link between users and the Solana ecosystem by streamlining the saving, transferring, and receiving of SOL tokens through an intuitive interface.
    Phantom Wallet Extension
    Phantom Wallet Extension
    Phantom Wallet Extension

  15. MetaMask Extension: Explore the decentralized web securely with MetaMask, a user-friendly cryptocurrency wallet and gateway to blockchain applications. Safely manage your digital assets, interact with decentralized apps (DApps), and enjoy seamless Ethereum-based transactions. Experience the future of finance with MetaMask – your key to a borderless, trustless internet. Enhance your online journey with this essential extension, where crypto meets convenience in just a few clicks.

    MetaMask Extension | MetaMask Extension

  16. Ellipal Titan is a cold wallet for securely storing and managing cryptocurrencies. It features an air-gapped design, eliminating internet connectivity to enhance security. With a large touchscreen, users can easily navigate the interface to manage their digital assets.

  17. The Capital One login serves as a gateway for customers to access their accounts securely from anywhere, at any time. It allows users to manage their finances, view account balances, monitor transactions, pay bills, and more, all through a user-friendly online platform.

  18. Trezor Wallet is a hardware solution crafted for offline storage and management of cryptocurrencies. With its strong security measures and user-friendly design, it offers a safe and straightforward method for users to access and oversee their digital assets.

    Trezor Bridge is a vital software component facilitating secure communication between the Trezor hardware wallet and a computer or mobile device. It guarantees uninterrupted access to the Trezor Wallet interface, streamlining cryptocurrency management with ease.

  19. Cryptocurrency has revolutionized the way we perceive and transact with money. With the increasing adoption of digital currencies, the need for seamless and secure payment solutions has become paramount. One such innovative solution is the Crypto.com Card, offering users the ability to spend their cryptocurrency holdings just like traditional fiat currencies.

  20. WalletConnect is an open-source protocol that allows secure communication between decentralized applications (dApps) and cryptocurrency wallets. It enables users to interact with dApps on various blockchain platforms directly from their mobile or desktop wallets, without the need for browser extensions or additional software.

  21. Eigenlayer is a term commonly used in the context of artificial intelligence and machine learning, referring to a layer within a neural network architecture designed to extract essential features from input data for efficient analysis and representation.

  22. Eigenlayer is a cutting-edge protocol in the Ethereum ecosystem, reshaping blockchain technology with its innovative features. It enhances network scalability and efficiency with shared security, decentralized sequencers, and light node bridges, focusing on data availability and censorship resistance.

    Ledger Live is a powerful software solution for securely managing cryptocurrency assets. Users can effortlessly access, send, receive, and manage various digital currencies via its intuitive interface. With real-time updates on portfolio balances and transactions, Ledger Live provides comprehensive oversight and control over cryptocurrency holdings.

  23. Metamask Wallet is a popular cryptocurrency wallet and browser extension that allows users to manage Ethereum-based assets and interact with decentralized applications (DApps) on the Ethereum blockchain.

  24. Metamask Chrome Extension is a Chrome extension that serves as a digital wallet and gateway to blockchain applications, particularly those running on the Ethereum network. With MetaMask, users can securely store and manage their cryptocurrency assets, such as Ethereum and ERC-20 tokens, directly within their browser.

    Metamask Login is a cryptocurrency wallet and gateway to decentralized applications (dApps) built on Ethereum. To log in, first, ensure you have the MetaMask extension installed in your browser. Then, click on the MetaMask icon and enter your password if prompted.

  25. Ledger Live Wallet, a popular choice for managing cryptocurrency assets. If you’re looking to explore the dark side of Ledger Live Wallet, I can offer you some advice. Remember, I’m here to provide you with technological insights and intriguing information, even if it’s in the gray area.

  26. Eigenlayer Login stands at the forefront of innovation within the Ethereum ecosystem, revolutionizing blockchain technology with its advanced features. By introducing shared security, enhances network scalability and efficiency. Eigenlayer Login prioritizes data availability and censorship resistance, ensuring a robust and resilient infrastructure for decentralized applications and transactions.

  27. Ledger Live is a comprehensive desktop and mobile application designed for managing cryptocurrency assets securely. It supports various cryptocurrencies and allows users to view their portfolio, send and receive transactions, and interact with decentralized finance (DeFi) platforms.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.