question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Authentication in Azure Devops

See original GitHub issue

Hi,

I want to use SDK inside a pipeline task. But I get token in another task as follow:

$token= $( az account get-access-token --resource=https://management.azure.com --query accessToken) Write-Host("##vso[task.setvariable variable=api-token;issecret=true]$token")

Is there anyway to use this token with SDK? Because I get token with service connection and I don’t store client and tenant info in environment variables.

Any advice would be appreciated.

Best

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anotherancientaliencommented, Feb 3, 2022

@mccoyp A million thanks!

0reactions
mccoypcommented, Feb 3, 2022

Hi @anotherancientalien, thank you for opening an issue and providing additional information! If you’d like to use the access token directly and don’t need/want a credential to automatically refresh it, this sample from azure-identity should be what you’re looking for. After declaring a StaticTokenCredential type like the sample shows, you can do something like the following:

credential = StaticTokenCredential(token)  # token is the access token acquired from the Azure CLI
backup_client = RecoveryServicesBackupClient(credential, subscription_id)

Note that you will still have to provide the subscription ID and that the credential won’t be usable after the access token expires.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guidance for authentication - Azure DevOps - Microsoft Learn
A: The best practice is to have different authentication paths for Azure DevOps Server and Azure DevOps Services. You can use the requestContext ......
Read more >
About security, authentication, and authorization
Authentication verifies an account identity based on the credentials provided when they sign into Azure DevOps. These systems integrate with and ...
Read more >
Use personal access tokens - Azure DevOps | Microsoft Learn
A personal access token contains your security credentials for Azure DevOps. A PAT identifies you, your accessible organizations, and scopes of ...
Read more >
Authorize access to REST APIs with OAuth 2.0 - Azure DevOps
Category Scope Name Agent Pools vso.agentpools Agent Pools (read) vso.agentpools_manage Agent Pools (read, manage) vso.environment_manage Environment (read, manage)
Read more >
Access your organization with Azure Active Directory
Azure DevOps no longer supports Alternate Credentials authentication since the beginning of March 2, 2020. If you're still using Alternate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found