Git Product home page Git Product logo

azureautomation / easily-obtain-accesstoken-bearer--from-an-existing-azazurerm-powershell-session Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 4 KB

You'll find in this function an easy way to extract the information required for you to build a Bearer token and all this from YOUR credentials within an authenticated PowerShell Azure session. You can then use this token to talk to Azure Resource Manager REST API.

License: Other

PowerShell 100.00%
azureautomationrunbookgallery

easily-obtain-accesstoken-bearer--from-an-existing-azazurerm-powershell-session's Introduction

Easily obtain AccessToken(Bearer) from an existing Az/AzureRM PowerShell session

The problematic

What you'll see on the Internet as a solution for this is creating an Application in your AAD with a ServicePrincipal, then use the ServicePrincipal credentials to obtain the AccessToken. Then problem is that this is very dependant on what RBAC permissions you give to your application, this is not what I really want, manage another entity permission just to get AccessTokens.

You also have a version that'll use the well-known PowerShell clientId & redirectUrl, preventing you from creating a new app in Azure AD but you'll still need to provide a username & password or clientId/password

 

Updates

2019-01-14 - Added support for both AzureRM & Az modules

 

What is proposed

You'll find in this function an easy way to extract the information required for you to build a Bearer token and all this from YOUR credentials within an authenticated PowerShell Azure session. You can then use this token to talk to Azure Resource Manager REST API.

 

An easier way to obtain your AccessToken

Include the code from included profile1.ps1 into your personnal PowerShell profile to make it easier to call the helper function when needed

Usually your personal PowerShell Profile should be at the following location:  $Home[My ]Documents\WindowsPowerShell\Profile.ps1

 

Overview

This is an overview of the code of the cmdlet Get-AzCachedAccessToken

  Usage   Requirements

Tested with Az.Accounts Version 1.x

Tested with AzureRM.Profile Version 2.x to 5.x

 

More information here:

https://www.codeisahighway.com/how-to-easily-and-silently-obtain-accesstoken-bearer-from-an-existing-azure-powershell-session/

TechNet gallery is retiring! This script was migrated from TechNet script center to GitHub by Microsoft Azure Automation product group. All the Script Center fields like Rating, RatingCount and DownloadCount have been carried over to Github as-is for the migrated scripts only. Note : The Script Center fields will not be applicable for the new repositories created in Github & hence those fields will not show up for new Github repositories.

easily-obtain-accesstoken-bearer--from-an-existing-azazurerm-powershell-session's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.