veerwest / formassembly-api

Example code for interacting with FormAssembly.com's OAuth2 API endpoints. Examples currently include PHP, Python, Bash, Salesforce.
31 stars 11 forks source link

Other oAuth2 grant types? #20

Open svu-aau opened 2 years ago

svu-aau commented 2 years ago

Hi,

We are hoping to write command line scripts to automate some processes that will update forms or check connectors. Does FA support other oAuth2 grant_types, like password? At first glance, I only notice authorization_code, which requires user interaction.

thanks, Steve

svu-aau commented 2 years ago

Bumping issue in hopes for a response. Thanks! Steve

edasque commented 2 years ago

After creating your application, obtaining your OAuth code interactively, you can use your authorization code to obtain your access token and refresh token and store those secrets for batch/CLI/scheduled jobs type use:

In a browser go to https://app.formassembly.com/oauth/login?type=web&client_id=CLIENT_ID&redirect_uri=DO_NOT_CHANGE&response_type=code

after replacing:

curl --location --request POST 'https://app.formassembly.com/oauth/access_token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=authorization_code' \ --data-urlencode 'type=web_server' \ --data-urlencode 'client_id=CLIENT_ID' \ --data-urlencode 'client_secret=CLIENT_SECRET' \ --data-urlencode 'redirect_uri=DO_NOT_CHANGE' \ --data-urlencode 'code=CODE_FROM_PREVIOUS_STEP'

This will return an access token, a refresh token which will be used to get a new access token in the future (after expire_in seconds):

{ "access_token": ACCESS_TOKEN, "expires_in": 315360000, "scope": null, "refresh_token": REFRESH_TOKEN }

svu-aau commented 2 years ago

Thanks @edasque!

I was able to get the access token and refresh token using your directions.

Can you please also provide the curl example on how to get a new access token using the refresh token? I tried to use the same curl code above with the following changes:

  1. changed the grant_type to refresh_token
  2. removed the code param
  3. added refresh_token param and set it to the refresh token received

So basically:

curl --location --request POST 'https://app.formassembly.com/oauth/access_token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'grant_type=refresh_token' \ --data-urlencode 'type=web_server' \ --data-urlencode 'client_id=CLIENT_ID' \ --data-urlencode 'client_secret=CLIENT_SECRET' \ --data-urlencode 'redirect_uri=DO_NOT_CHANGE' \ --data-urlencode 'refresh_token=myrefreshToken'

The response was:

{
    "error": "invalid_grant4"
}

thanks, Steve

svu-aau commented 2 years ago

hi @edasque , following up to see if you have an update to above question on how to use the refresh_token to get a new access_token.

much appreciated, Steve

edasque commented 2 years ago

Hi @svu-aau , it seems there is a bug around renewal of the token, we'll tackle it soon. In the mean time, the token is long lasting so you wouldn't need to refresh for a long while.

svu-aau commented 2 years ago

thanks @edasque !

siddiquam commented 1 year ago

Trying to access the FormAssembly login API image

https://ijm.tfaforms.net/oauth/access_token?type=web_server&client_id=4M8vQBMW5Zr5ygqi0NVX&redirect_uri=https://www.ijmindia.org&grant_type=authorization_code&code=IQDONQuC04VFKe3iS2iXMBrtCKcuNwiL&client_secret=hki7vgCNQGeaS8uvZs3Q

Getting an response as {"error":"invalid_grant1-2-14"}

Please advice