Created
February 4, 2020 16:11
-
-
Save chadwilken/3f25bfc8a1184078a762191b2ece9943 to your computer and use it in GitHub Desktop.
CompanyCam OAuth 2 Flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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