Go to All Forums

How to get access token for automation purpose

by Anuj

I am writing an automation which will automate all manual tasks like creation of user from particular customer, adding pagerduty from specific customer etc. One of the requirement is that this automation should authenticate and authorize the user who is running this automation. This is how my automation will run.

 

/usr/bin/python automation.py –operation useradd –customername customer1 –userdata ‘anuj:mailto:anujk@vmware.com’ –username anujk –password ‘password’

 

What have I done so far:

  1. Created one small flask web application. Logged in site24x7 api console and create web client as application. Provided name, callback url etc. It gave me client ID and secret
  2. Open web app in browser and click on authorize hyperlink. This will give access token.

 

Step2 is manual activity and I don’t want to use selenium because automation user may not have selenium python package installed. Therefore, I want to avoid step 2.

 

Automation should work as follow.

 

  1. Automation should take credential as input
  2. It should make a curl call which should yield access token

I want to achieve step2.

 

any help will be much appreciated. 

Like (4) Reply
Replies (2)

Re: How to get access token for automation purpose

Hi Anuj,

The main reason for using OAuth is to avoid sharing account credential with any third-party application. So each user need to manually approve your application via Zoho Accounts, our SSO service, at least once so that you can make api call in their name. You have to store the refresh token that you have received in your web application for reusing.

If the users are going to run the automation via terminal individually, they can hard code or pass the refresh token as an argument to the script.

Thillai.

Like (0) Reply

Re: Re: How to get access token for automation purpose

by Anuj
Hi Thillai,

This idea helped me. So here is how i am trying to make it.

1- user will allow web app to access site24x7. This will generate a refresh token. Backend logic will collect refresh token and UserID/username/ and store in DB.
2- when user will run automation web app's backend will get userid/username ==> do a lookup in DB ==> find refresh token ==> generate access token using refresh token.

I am facing issue while getting userID/username. Can you please help me on this.

My application is Flask application. I am getting below details but not userID

print request.args

ImmutableMultiDict([('state', u'14fac8d9-c848-464d-a5ca-684141333225'), ('code', u'1000.29562ed10bf27738a81d222aaf1c2703.2f844f1b6128485d220c40af8225de56'), ('location', u'us'), ('accounts-server', u'accounts.zoho.com')])






Like (0) Reply

Was this post helpful?