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

MFA (and possibly Okta) login help #120

Open
nick-moreno-cffc opened this issue Apr 15, 2022 · 7 comments
Open

MFA (and possibly Okta) login help #120

nick-moreno-cffc opened this issue Apr 15, 2022 · 7 comments
Assignees
Labels
question or help Clarification or help may suffice to resolve

Comments

@nick-moreno-cffc
Copy link

Having trouble configuring a connected app to utilize the OAuth login process, but I am having trouble breaking through.

The readme doesn't give too much explanation to how to log in via OAuth 2.0 - is it possible to have a more detailed walk through?

If not, running into the following issue:

  1. Hitting the following error when calling my connected app:
Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params,  : 
  Bad Request (HTTP 400). Failed to get an access token.
  1. Also unsure as to what callback url to add when configuring the connected app.

Any guidance would be very appreciated! We've resorted to OOTB Salesforce tools for data uploads but our team can work in R much faster.

@StevenMMortimer
Copy link
Owner

Hi @nick-moreno-cffc! You'll see that the OAuth key, secret, and callback URL are package options.

salesforcer/R/zzz.R

Lines 12 to 14 in a1e1e9c

salesforcer.consumer_key = "3MVG9CEn_O3jvv0yRMQezJ8PwesiIknRU9v9j778rv78UvJ2JTQzSG.QduxyMxYaldoNEhO0eVvw4ogCT58c5",
salesforcer.consumer_secret = "3471656211653393546",
salesforcer.callback_url = "http://localhost:1410/",

The default values correspond to a connected app that I have setup for others to use if they don't want to setup their own connected app. When you setup your own connected app, you should see its key and secret. I'd recommend using the same callback URL (http://localhost:1410/). After setting up the app, you'd just have to set those values as options in the top of your R scripts to authenticate using the app, like this:

options(salesforcer.consumer_key = "YOUR APP KEY")
options(salesforcer.consumer_secret = "YOUR APP SECRET")
options(salesforcer.callback_url = "http://localhost:1410/")  # only needed if you use a different callback URL

See below for screenshots of the two sections that I configured when setting up my app: 1) 'API (Enable OAuth Settings)' and 2) 'OAuth Policies'. If this is new to you, then I'd highly recommend reading the Salesforce documentation Create a Connected App and start with Configure Basic Connected App Settings

API (Enable OAuth Settings)
image

OAuth Policies - I'd recommend setting "Refresh token is valid until revoked"
image

@StevenMMortimer StevenMMortimer added the question or help Clarification or help may suffice to resolve label Apr 23, 2022
@nick-moreno-cffc
Copy link
Author

Thank you for the step-by-step!

I created the connected app and I'm running into what seems to be a common issue:
error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

I think it has something to do with either the start or callback url? I tried your suggested URl as well as the suggested callback from Okta's documentation: https://system-admin.okta.com/admin/app/generic/oauth20redirect

Any thoughts?

Thank you, Steven!
Nick

@StevenMMortimer
Copy link
Owner

@nick-moreno-cffc In the past I have noticed that the callback url should start with http:// not https://. Can you double check that you're using http://? Apologies in advance if it seems like I'm grasping at things potential fixes. I am by no means an expert in this.

@StevenMMortimer
Copy link
Owner

@nick-moreno-cffc Let me know if you have further questions or if you've figured things out so I can note what worked. I'll close the issue in a few days if I don't hear back. Thanks!

@StevenMMortimer
Copy link
Owner

Hi @nick-moreno-cffc – Let me know if you resolved or are still having issues. Happy to think through a few other solutions, if needed. If not, then I'll close this since it's been open for a few months.

At some point, I'll probably create a vignette with this info so it's more structured, so thanks for giving me the chance to put some thoughts on paper to hopefully help some other folks trying to do the same thing.

@ghareesh
Copy link

ghareesh commented Sep 8, 2022

I opened another ticket on same ..
I either get local host not found (with httpuv package installed). And R console says awaiting for browser authentication..

If I uninstall httpuv, it shows error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

@camraynor
Copy link

I was running into the same redirect_uri_mismatch error and found that the issue was that the package I was using (httr2) was adding an extra http:// prefix for localhost so it was trying to redirect to http://http://localhost:1410. I noticed this by checking the redirect_uri url variable on the error page in browser. E.g.:

https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=XXXXX&redirect_uri=http%3A%2F%2Fhttp%3A%2F%2Flocalhost%3A1410%2F&state=XXXXX&code_challenge=XXXXX&code_challenge_method=S256

@nick-moreno-cffc it sounds like something similar could be happening with the Okta redirect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question or help Clarification or help may suffice to resolve
Projects
None yet
Development

No branches or pull requests

4 participants