-
Notifications
You must be signed in to change notification settings - Fork 3
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
10 changed files
with
589 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<html> | ||
<head> | ||
<script src='../dist/bouquet.js'></script> | ||
<script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.18.10/URI.min.js"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<h1>Example of authentication using bouquet.js</h1> | ||
<p> | ||
Bouquet Server URL (apiUrl) <br> | ||
<b id="apiUrl"></b> | ||
<p> | ||
Client Id (clientId) <br> | ||
<b id="clientId"></b> | ||
</p> | ||
<div id='root'> </div> | ||
|
||
<script> | ||
$(function() { | ||
|
||
// process query parameters parameter | ||
var uri = new URI(); | ||
var apiUrl = uri.query(true).apiUrl; | ||
if (!apiUrl) { | ||
apiUrl = "//demo.openbouquet.io/release/v4.2"; | ||
} | ||
$("#apiUrl").html(apiUrl); | ||
var clientId = uri.query(true).clientId; | ||
if (!clientId) { | ||
clientId = "ob1"; | ||
} | ||
$("#clientId").html(clientId); | ||
var code = uri.query(true).code; | ||
|
||
// create a new Bouquet client | ||
var bouquet = new Bouquet({ | ||
url : apiUrl, | ||
clientId : clientId, | ||
code : code | ||
}); | ||
|
||
document.getElementById('root').innerHTML = "Connecting..."; | ||
// step 1 | ||
bouquet.request("/rs/user") | ||
.then(function(user) { | ||
var html = "Connected with user : "+user.email; | ||
html += " <a href='https://cloud.openbouquet.io#logout'>Logout</a>" | ||
document.getElementById('root').innerHTML = html; | ||
}) | ||
.catch(function(err) { | ||
if (err.body) { | ||
if (err.body.loginURL) { | ||
// get bouquet server teamId | ||
bouquet.request("/rs/status") | ||
.then(function(status) { | ||
var loginUrl = new URI(err.body.loginURL); | ||
loginUrl.setQuery("client_id",bouquet.config.clientId); | ||
loginUrl.setQuery("redirect_uri", window.location.href); | ||
loginUrl.setQuery("teamId", status.teamId); | ||
document.getElementById('root').innerHTML = "<a href='"+loginUrl.toString()+"'>Please Sign-In</a>"; | ||
}) | ||
.catch(function(err) { | ||
document.getElementById('root').innerHTML = "Failed to connect: "+err; | ||
}); | ||
} else { | ||
document.getElementById('root').innerHTML = "Authentication failed: "+err.body.error; | ||
} | ||
} else { | ||
document.getElementById('root').innerHTML = "Authentication failed: "+err; | ||
} | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.