Client Side Authorization Flow
Client side authentication and authorization flow is very similar to the server side flow. The difference is in the parameters passed to the server and in the response fields that you get back. Authentication & AuthorizationTo enter the authentication/authorization client-side flow, you must pass the following parameters to the authorization URL: Oauth URL
https://www.geni.com/platform/oauth/authorize
Parameters
Example
https://www.geni.com/platform/oauth/authorize?client_id=YOUR_APP_KEY&redirect_uri=YOUR_URL&response_type=token
If the user is already logged in, we validate the login cookie that we have stored on the user's browser and authenticate the user.If the user is not logged in, they are prompted to enter their credentials:
Once we have successfully authenticated the user, we will prompt the user to authorize your application:
If the user presses Don't Allow, your app is not authorized.The user will be redirected (via HTTP 302) to the URL you passed in the redirect_uri parameter with the following error information: Returned Fields
Example
http://YOUR_URL#status=unauthorized&message=user+canceled
If the user presses Allow, your app is authorized.The user will be redirected (via HTTP 302) to the URL you passed in the redirect_uri parameter with an authorization code: Returned Fields
Example
http://YOUR_URL#access_token=ACCESS_TOKEN_GENERATED_BY_SERVER&expires_in=SECONDS_UNTIL_IT_IS_EXPIRED
Cross Domain API CallsGeni Platform supports cross-domain API calls using JSONP framework. Below is a simple example for Geni JSONP API call. You must provide a valid access token in order to make an JSONP API call. Examplevar Geni = {callbacks:{}, client_id:"YOUR_APP_KEY", access_token:""}; function jsonp(url, params, callback) { var script = document.createElement('script'); var g_uuid = 'g' + (((1+Math.random())*0x10000)|0).toString(16).substring(1); params = params || {}; params['callback'] = 'Geni.callbacks.' + g_uuid; var query = []; for(var p in params) str.push(encodeURIComponent(p) + "=" + encodeURIComponent(params[p])); query = query.join("&"); url = url + (url.indexOf('?')>-1 ? '&' : '?') + query; Geni.callbacks[g_uuid] = function(data) { if(callback) callback(data); delete Geni.callbacks[g_uuid]; } script.src = url; document.getElementsByTagName('head')[0].appendChild(script); } // Parse access token from the URL if it is available if (Geni.access_token == "") { var params = {}; var anchor = window.location.href.split("#"); if (anchor.length > 1) { var parts = anchor[1].split("&"); for (var i=0; i < parts.length; i++) { var values = parts[i].split("="); params[values[0]] = values[1]; } } // Add code to store/retrieve access token from a cookie Geni.access_token = params["access_token"]; } if (Geni.access_token == "") { window.location = "https://www.geni.com/oauth/authorize?client_id" + Geni.client_id + "&redirect_uri=" + window.location.href + "&response_type=token"; } else { // Get profile data jsonp("/profile", {access_token:Geni.access_token}, function(data) { alert("Hello " + data["name"]); }) } Geni JavaScript Client SDKGeni Platform comes with a full featured JavaScript library that allows you to build dynamic web applications in the browser with Geni's data. It supports authentication, autherization and API calls to get the site data. |