Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization code error for posit workbench rstudio ide #86

Open
blackheartweb opened this issue Aug 16, 2024 · 3 comments
Open

Authorization code error for posit workbench rstudio ide #86

blackheartweb opened this issue Aug 16, 2024 · 3 comments

Comments

@blackheartweb
Copy link

I am using azure auth in posit workbench rstudio ide which hosted on RHEL8 Linux azure server. Every time device code , the authentication is happening but for Authorization-code, the authentication is not happening.

I get localhost not found for the port 1410. It works normally in Rstudio ide

@mattmalcher
Copy link

You need to change your redirect URI.

your browser will be going to localhost on your desktop machine, where there is nothing running.

You can to use the rserver-url command or rstudioapi::translateLocalUrl to generate a proxy address which will allow your browser to reach localhost on workbench.

if you are wedded to the authorisation code flow,
note this will probably require a change to your Azure AD app, and the random nature of the proxy address will mean you need a wildcard in the redirect URI allow pattern.

@blackheartweb
Copy link
Author

Hello Mattmalcher,
Thankyou for your response
I ran the rstudioapi:: translateLocalUrl ("http://localhost:1410")
I got output similar to this "p/77c02a62".

Below is the script I am running, I have appended the above output to redirect uri.

library(AzureAuth)
redirect <-"https://workbench.com/s/33cea31def16dca/p/77c02a62"
token <- AzureAuth::get_azure_token( "https://management.azure.com/",
"mytenant",
"app_id",
use_cache = FALSE,
auth_type = "authorization_code" authorize_args=list(redirect_uri=redirect)
)

When I run this I get the following error

Error: Expecting a single value: [extent=0].

Also I tried replace redirect uri with http://localhost:1410/p/77c02a62

library(AzureAuth)
redirect <- "http://localhost:1410/p/77c02a62/"
token <- AzureAuth::get_azure_token( "https://management.azure.com/",
"mytenant",
"app_id",
use_cache = FALSE,
auth_type = "authorization_code" authorize_args=list(redirect_uri=redirect) )

I get a browser window opened with "AADSTS50011: The redirect URI 'https://localhost:1410' specified in the request does not match the redirect URIs configured for the application. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal"

When I set an redirect uri in my azure application and run the above code , I am again getting localhost refused to connect error.

Any suggestions would be much appreciated.

@MizzoMazzo
Copy link

Hello,

has there been any action yet?
I currently have the exact same problem.

We are using Posit IDE hosted via Kubernetes which means we need to configure the redirect_uri in order for the authentication to work properly. We are trying to get some sharepoint resources like this

library(AzureAuth)
library(AzureGraph)
library(Microsoft365R)

tenant = "tenant-id"
site_url = "site-url"
app = "app-id"
redirect = "https://workbench-url.com"

# Add sensitive variables as environmental variables so they aren't exposed
user <- rstudioapi::askForSecret("user")
pwd <- rstudioapi::askForSecret("pwd")
app_secret <- rstudioapi::askForSecret("app_secret")

# Create auth token cache directory, otherwise it will prompt the user on the console for input
create_AzureR_dir()

# create a Microsoft Graph login
gr <- create_graph_login(tenant, app, 
                         username = user, 
                         password = pwd,
                         token_args = list(client_secret = app_secret), 
                         auth_type="authorization_code",
                         authorize_args=list(redirect_uri=redirect))

# An example of using the Graph login to connect to a SharePoint site
site <- gr$get_sharepoint_site(site_url)

This results in the error Error: Expecting a single value: [extent=0]

Due to the nature of our setup we are depending on the abillity to set the redirect_uri.
Leaving the redirect_uri from the authorize_args will result in a poput window opening and obviously complaining about the wrong redirect_uri.
I tried debugging but I could not find the issue that is present here since we are also following all available documentation regarding the use of authorize_args.

Would greatly appreciate any further help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants