Skip to content

Instantly share code, notes, and snippets.

@chadwilken
Created February 4, 2020 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwilken/3f25bfc8a1184078a762191b2ece9943 to your computer and use it in GitHub Desktop.
Save chadwilken/3f25bfc8a1184078a762191b2ece9943 to your computer and use it in GitHub Desktop.
CompanyCam OAuth 2 Flow
require 'oauth2'
client_id = 'your_client_id'
client_secret = 'your_client_secret'
redirect_uri = 'https://yoursite.com/oauth/authorize'
site = 'https://app.companycam.com'
client = OAuth2::Client.new(client_id, client_secret, site: site)
auth_url = client.auth_code.authorize_url(redirect_uri: redirect_uri, scope: 'read write destroy')
# Visit this URL and click "Authorize"
code = params[:code]
token = client.auth_code.get_token(code, redirect_uri: redirect_uri)
# Store
# token.token
# token.refresh_token
# token.expires_at
# Make a request
response = token.get('/v2/projects')
projects = JSON.parse(response.body)
# After the token is expired
new_token = token.refresh!
# Store new_token.token and new_token.refresh_token like above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment