How to use httr2 devicecode authentication to Azure Active Directory?

I'm looking at converting my AzureAuth package to use httr2, and running into a problem with device code authentication. It's a bit hard to give a reproducible example due to access restrictions, but here's the gist of it.

cli_app <- "xxx-yyy-zzz"
scopes <- paste(c("https://management.azure.com/.default", "openid", "offline_access"),
                collapse=" ")
tenant <- "mytenant"


# authenticating with AzureAuth/httr is ok
devtok <- AzureAuth::get_azure_token(scopes, tenant, app=cli_app, version=2,
                                     auth_type="device_code")


# authenticating with httr2's device code functionality fails
dev_url <- paste0("https://login.microsoftonline.com/",
                  tenant,
                  ".onmicrosoft.com/oauth2/v2.0/devicecode")
token_url <- paste0("https://login.microsoftonline.com/",
                    tenant,
                    ".onmicrosoft.com/oauth2/v2.0/token")
dev_client <- oauth_client(cli_app, token_url)
devtok2 <- oauth_flow_device(dev_client, auth_url=dev_url, scope=scopes)
# Error: Failed to process response from 'token' endpoint

Where is the error in how I'm calling the httr2 functions?

Note that I can authenticate with the authorization code flow, it's device code that's causing problems. As an aside, it's rather hard to debug this in httr2 since the package now automatically converts HTTP errors into R errors; while there's a way to override this for regular requests, I haven't found a way to do it for the Oauth code.

This is a bug in httr2 0.1.1:

Can't get device code authentication to work · Issue #87 · r-lib/httr2 (github.com)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.