scripts/sinatra/views/index.erb
<!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 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 OAuthCode(config);
</script>
</head>
<body>
<h1>Medium 3-Legged OAuth Demo in Ruby</h1>
<p><input type="button" onclick="oauth.loginPopup()" value="Login with Medium"></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>