I want to fetch data from the application where it uses OAuth token for authentication via API.
Generated OAuth token is valid for 30 days. After that I have to generate new token.
Currently I am generating OAuth token for each request to the application (internal project) before making each request as below
def generate_token
end
def get(path)
generate_token
end
def fetch_customer_details
get(path)
end
def fetch_employee_details
get(path)
end
How can I avoid generating token for each request and make the request to fetch data without authorisation issue?
You need to store the token somewhere in between requests, and fetch that value (instead of generating new token). Probably the best way is to use Session for this:
def generate_token
session[:oauth_token] = generate_your_actual_token
end
def get(path)
session[:oauth_token] || generate_token
end
def fetch_customer_details
get(path)
end
def fetch_employee_details
get(path)
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.