-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
132 additions
and
116 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
source ENV['GEM_SOURCE'] || "https://rubygems.org" | ||
|
||
gem 'ringcentral_sdk' | ||
gem 'sinatra' | ||
gem 'sinatra' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!ruby | ||
|
||
require 'sinatra' | ||
require 'multi_json' | ||
require 'ringcentral_sdk' | ||
|
||
# Create and edit the .env file: | ||
# $ cp config-sample.env.txt .env | ||
|
||
client = RingCentralSdk::REST::Client.new do |config| | ||
config.load_env = true | ||
end | ||
|
||
set :logger, Logger.new(STDOUT) | ||
set :port, ENV['MY_APP_PORT'] | ||
|
||
get '/' do | ||
token_json = client.token.nil? \ | ||
? '' : MultiJson.encode(client.token.to_hash, pretty: true) | ||
|
||
state = rand(1000000) | ||
logger.info("OAuth2 Callback Request State #{state}") | ||
|
||
erb :index, locals: { | ||
authorize_uri: client.authorize_url(state: state), | ||
redirect_uri: client.config.redirect_url, | ||
token_json: token_json} | ||
end | ||
|
||
get '/callback' do | ||
code = params.key?('code') ? params['code'] : '' | ||
state = params.key?('state') ? params['state'] : '' | ||
logger.info("OAuth2 Callback Response State #{state}") | ||
token = client.authorize_code(code) if code | ||
'' | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RC_APP_KEY=myAppKey | ||
RC_APP_SECRET=myAppSecret | ||
RC_SERVER_URL=https://platform.devtest.ringcentral.com | ||
RC_APP_REDIRECT_URL=http://localhost:8080/callback | ||
MY_APP_HOST=localhost | ||
MY_APP_PORT=8080 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | ||
<script> | ||
var auth_url = '<%= authorize_url %>'; | ||
|
||
$.oauthpopup = function(options) | ||
{ | ||
options.windowName = options.windowName || 'ConnectWithOAuth'; // should not include space for IE | ||
options.windowOptions = options.windowOptions || 'location=0,status=0,width=400,height=660'; | ||
options.callback = options.callback || function(){ window.location.reload(); }; | ||
var that = this; | ||
console.log(options.path); | ||
that._oauthWindow = window.open(options.path, options.windowName, options.windowOptions); | ||
that._oauthInterval = window.setInterval(function(){ | ||
if (that._oauthWindow.closed) { | ||
window.clearInterval(that._oauthInterval); | ||
options.callback(); | ||
} | ||
}, 1000); | ||
}; | ||
|
||
function Auth3l(rcDemo) { | ||
var t=this; | ||
t.authorize = function() { | ||
var urltoopen = '<%= authorize_url %>'; | ||
$.oauthpopup({ | ||
path: urltoopen, | ||
callback: function() | ||
{ | ||
console.log('callback'); | ||
<head> | ||
<meta charset="UTF-8"> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | ||
<script> | ||
|
||
var config = { | ||
authUri: '<%= authorize_uri %>', | ||
redirectUri: '<%= redirect_uri %>', | ||
} | ||
|
||
var OAuthCode = function(config) { | ||
this.config = config; | ||
this.loginPopup = function() { | ||
this.loginPopupUri(this.config['authUri'], this.config['redirectUri']); | ||
} | ||
this.loginPopupUri = function(authUri, redirectUri) { | ||
var win = window.open(authUri, 'windowname1', 'width=800, height=600'); | ||
|
||
var pollOAuth = window.setInterval(function() { | ||
try { | ||
console.log(win.document.URL); | ||
if (win.document.URL.indexOf(redirectUri) != -1) { | ||
window.clearInterval(pollOAuth); | ||
win.close(); | ||
location.reload(); | ||
} | ||
} catch(e) { | ||
console.log(e) | ||
} | ||
}); | ||
}, 100); | ||
} | ||
} | ||
|
||
var oauth = new Auth3l(); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<h1>3-Legged OAuth 2.0 Demo</h1> | ||
<p>To run this demo use the following command:</p> | ||
<p>$ ruby oauth.rb</p> | ||
<p><input type="button" onclick="oauth.authorize()" value="Login with RingCentral"></p> | ||
<p>App Key: <%= app_key %></p> | ||
<p>Authorization URL: <%= authorize_url %></p> | ||
<p>Redirect URL: <%= redirect_uri %></p> | ||
</body> | ||
</html> | ||
var oauth = new OAuthCode(config); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<h1>RingCentral 3-Legged OAuth Demo in Ruby</h1> | ||
|
||
<p><input type="button" onclick="oauth.loginPopup()" value="Login with RingCentral"></p> | ||
|
||
<p>Access Token</p> | ||
<pre style="background-color:#efefef;padding:1em;overflow-x:scroll"><%= token_json %></pre> | ||
|
||
<p>More info:</p> | ||
<ul> | ||
<li><a href="https://developer.ringcentral.com/api-docs/latest/index.html#!#AuthorizationCodeFlow">RingCentral API Developer Guide</a></li> | ||
<li><a href="https://github.com/grokify/ringcentral-oauth-demos">GitHub repo</a> | ||
<li><a href="https://github.com/grokify/ringcentral-oauth-demos/tree/master/ruby-sinatra">GitHub repo Ruby README</a></p> | ||
</ul> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.