(function () { 'use strict'; window.ngOauth3App = angular.module('oauth3Playground', [ 'oauth3.org' ]) //window.ngOauth3App = angular.module('oauth3Playground', [ 'ui.router' ]) /* ngOauth3App.config(function($stateProvider) { var helloState = { name: 'hello', url: '/hello', template: '

hello world!

' } var aboutState = { name: 'about', url: '/about', template: '

Its the UI-Router hello world app!

' } $stateProvider.state(helloState); $stateProvider.state(aboutState); }); */ .controller('PlaygroundCtrl', [ 'azp@oauth3.org', function (OAUTH3) { // NOTE: This OAUTH3 is the same as window.OAUTH3, but with angular's promise injected // TODO: how to load more than one version of oauth3 on the page (i.e. a vanilla version without angular entaglement) var vm = this; vm.clientUri = OAUTH3.clientUri(window.location); vm.conf = { client_id: vm.clientUri, client_uri: vm.clientUri, provider_uri: vm.clientUri }; vm.providerUri = vm.conf.client_uri; // // Convenience for our app // vm.fn = {}; vm.fn.lock = function () { vm._working = true; }; vm.fn.unlock = function () { vm._working = false; }; vm.fn.clearError = function () { vm.error = null; }; vm.fn.clearDirectives = function () { vm.directives = null; }; // // Wrap around the OAUTH3 APIs // vm.api = {}; vm.api.providerUri = function () { console.log('[DEBUG] providerUri:', vm.providerUri); try { vm.providerUri = OAUTH3.uri.normalize(vm.providerUri); vm.conf.provider_uri = vm.providerUri; } catch(e) { vm.error = e; } }; vm.api.clientUri = function () { console.log('[DEBUG] clientUri:', vm.clientUri); try { vm.clientUri = OAUTH3.clientUri({ host: vm.clientUri }); if (vm.clientUri) { console.log('[DEBUG] clientUri:', vm.clientUri); vm.conf.client_uri = vm.clientUri; vm.conf.client_id = vm.clientUri; } } catch(e) { vm.error = e; } }; vm.api.discover = function () { vm.fn.lock(); vm.discoveryObj = OAUTH3.urls.discover(vm.conf.provider_uri, vm.conf); vm.directivesUrl = OAUTH3.url.normalize(vm.conf.provider_uri) + '/' + vm.discoveryObj.query._pathname; vm.discoveryUrl = vm.discoveryObj.method + ' ' + vm.discoveryObj.url; return OAUTH3.discover(vm.conf.provider_uri, vm.conf).then(function (dir) { console.log('[DEBUG] directives:'); console.log(dir); vm.directives = JSON.stringify(dir, null, 2); }, function (err) { vm.error = err; }).then(function () { vm.fn.unlock(); }); }; } ] ); }()); window.PLAYGROUND = function () { /* 'use strict'; console.log("Welcome to the Playground!"); var clientUri = OAUTH3.clientUri(window.location); $('input.js-provider-uri').val(window.location.host); $('span.js-provider-uri').text(window.location.host); $('body').on('keyup', '.js-provider-uri', function () { $('span.js-provider-uri').text($('input.js-provider-uri').val()) }); $('body').on('click', '.js-discover', function () { $('.js-discover').attr('disabled', 'disabled'); console.log('discover clicked!'); var providerUri = $('input.js-provider-uri').val(); return OAUTH3.discover(providerUri, { client_uri: clientUri }).then(function (dir) { console.log('[DEBUG] directives:'); console.log(dir); $('.js-directives').val(JSON.stringify(dir, null, 2)); }, function (err) { console.error('[DEBUG] error:'); console.error(err); }).then(function () { $('.js-discover').removeAttr('disabled'); }); }); */ };