A client-side JavaScript SDK for authenticating with OAuth2 (and OAuth1 with a oauth proxy) web services and querying their REST APIs. HelloJS standardizes paths and responses to common APIs like Google Data Services, Facebook Graph and Windows Live Connect. It's modular, so that list is growing. No more spaghetti code!
See demo at https://adodson.com/hello.js/.
Here are some more demos...
| Windows | More.. | |||
|---|---|---|---|---|
| Profile: name, picture (email) | ✓ | ✓ | ✓ | |
| Friends/Contacts: name, id (email) | ✓ | ✓ | ✓ | |
| Albums, name, id, web link | ✓ | ✓ | ✓ | |
| Photos in albums, names, links | ✓ | ✓ | ✓ | |
| Photo file: url, dimensions | ✓ | ✓ | ✓ | |
| Create a new album | ✓ | ✓ | ||
| Upload a photo | ✓ | ✓ | ||
| Delete an album | ✓ | ✗ | ||
| Status updates | ✗ | ✓ | ✓ | |
| Update Status | ✓ | ✓ | ✗ |
Download: HelloJS | HelloJS (minified)
Compiled source, which combines all of the modules, can be obtained from GitHub, and source files can be found in Source.
Note: Some services require OAuth1 or server-side OAuth2 authorization. In such cases, HelloJS communicates with an OAuth Proxy.
npm i hellojs
At the present time only the bundled files in the /dist/hello.* support CommonJS. e.g. let hello = require('hellojs/dist/hello.all.js').
bower install hello
The Bower package shall install the aforementioned "/src" and "/dist" directories. The "/src" directory provides individual modules which can be packaged as desired.
Quick start shows you how to go from zero to loading in the name and picture of a user, like in the demo above.
Register your application with at least one of the following networks. Ensure you register the correct domain as they can be quite picky.
<script src="https://github.com/MrSwitch/hello.js/raw/v2.0.0-4/dist/hello.all.js"></script>
Just add onclick events to call hello(network).login(). Style your buttons as you like; I've used zocial css, but there are many other icon sets and fonts.
<button onclick="hello('windows').login()">windows</button>
Let's define a simple function, which will load a user profile into the page after they sign in and on subsequent page refreshes. Below is our event listener which will listen for a change in the authentication event and make an API call for data.
hello.on('auth.login', function(auth) {
// Call user information, for the given network
hello(auth.network).api('me').then(function(r) {
// Inject it into the container
var label = document.getElementById('profile_' + auth.network);
if (!label) {
label = document.createElement('div');
label.id = 'profile_' + auth.network;
document.getElementById('profile').appendChild(label);
}
label.innerHTML = '<img src="https://github.com/MrSwitch/hello.js/raw/v2.0.0-4/' + r.thumbnail + '" /> Hey ' + r.name;
});
});
Now let's wire it up with our registration detail obtained in step 1. By passing a [key:value, ...] list into the hello.init function. e.g....
hello.init({
facebook: FACEBOOK_CLIENT_ID,
windows: WINDOWS_CLIENT_ID,
google: GOOGLE_CLIENT_ID
}, {redirect_uri: 'redirect.html'});
That's it. The code above actually powers the demo at the start so, no excuses.
Initiate the environment. And add the application credentials.
| name | type | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| credentials | object( key => value, ... )
|
||||||||||||||||||
| options | sets default options, as in hello.login() |
hello.init({
facebook: '359288236870',
windows: '000000004403AD10'
});
If a network string is provided: A consent window to authenticate with that network will be initiated. Else if no network is provided a prompt to select one of the networks will open. A callback will be executed if the user authenticates and or cancels the authentication flow.
| name | type | example | description | argument | default | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| network | string | windows, |
One of our services. | required | null | ||||||||||||||||||||||||||||||||||||||||||||
| options | object
|
||||||||||||||||||||||||||||||||||||||||||||||||
| callback | function | function(){alert("Logged in!");} |
A callback when the users session has been initiated | optional | null |
hello('facebook').login().then(function() {
alert('You are signed in to Facebook');
}, function(e) {
alert('Signin error: ' + e.error.message);
});
Remove all sessions or individual sessions.
| name | type | example | description | argument | default | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| network | string |
windows, |
One of our services. | optional | null | ||||||||
| options | object
|
||||||||||||
| callback | function |
function() {alert('Logged out!');}
|
A callback when the users session has been terminated | optional | null |
hello('facebook').logout().then(function() {
alert('Signed out');
}, function(e) {
alert('Signed out error: ' + e.error.message);
});
Get the current status of the session. This is a synchronous request and does not validate any session cookies which may have expired.
| name | type | example | description | argument | default |
|---|---|---|---|---|---|
| network | string | windows, |
One of our services. | optional | current |
```js var online = function(session) { var currentTime = (new Date()).getTime() / 1000; retur
$ claude mcp add hello.js \
-- python -m otcore.mcp_server <graph>