@@ -515,51 +515,92 @@ function setSelectedClientSecrets() {
515515 $('#client_secret').val('');
516516 }
517517}
518+ function setSelectedClientSecrets() {
519+ selectedClient = _.find(clients, { 'client_id': $('#client').val() });
520+
521+ if (selectedClient) {
522+ $('#client_id').val(selectedClient.client_id);
523+ $('#client_secret').val(selectedClient.client_secret);
524+ } else {
525+ $('#client_id').val('');
526+ $('#client_secret').val('');
527+ }
528+ }
529+ function handleSuccessRequest(url, opt, data) {
530+ data.request = opt;
531+ if (data.refresh_token) {
532+ $('#refresh_token').val(data.refresh_token);
533+ }
534+ if (data.request.password) {
535+ data.request.password = '*****************';
536+ }
537+ if (data.request.client_secret) {
538+ data.request.client_secret = '*****************';
539+ }
540+ $.ajax({ type: "POST", url: '{{baseUrl}}/request', data: JSON.stringify(data), contentType: 'application/json' })
541+ .done(function (data) {
542+ $('#modal-body').html(data);
543+ $('#modal-body').prepend($('<pre/>', { 'class': 'json-object', 'html': 'POST ' + url }));
544+ })
545+ .fail(function (err) {
546+ $('#modal-body').html('<p>Error decoding the response.</p>');
547+ $('<pre/>', { 'class': 'json-object', 'html': err.responseText || err.name || err.text || err.body || err.status }).appendTo('#modal-body');
548+ });
549+ }
550+ function handleErrorRequest(url, opt, err) {
551+ if (opt.password) {
552+ opt.password = '*****************';
553+ }
554+ if (opt.client_secret) {
555+ opt.client_secret = '*****************';
556+ }
557+ $.ajax({ type: "POST", url: '{{baseUrl}}/request', data: JSON.stringify({ request: opt, err: err }), contentType: 'application/json' })
558+ .done(function (data) {
559+ $('#modal-body').html(data);
560+ $('#modal-body').prepend($('<pre/>', { 'class': 'json-object', 'html': 'POST ' + url }));
561+ })
562+ .fail(function (err) {
563+ $('#modal-body').html('<p>Error decoding the response.</p>');
564+ $('<pre/>', { 'class': 'json-object', 'html': err.responseText || err.name || err.text || err.body || err.status }).appendTo('#modal-body');
565+ });
566+ }
518567function executeRequest(title, url, opt) {
519568 save();
520569 $('#modal-title').html(title);
521570 $('#modal-body').html('Loading...');
522571 $('#modal-dialog').modal({ show: true });
523572 $.post(url, opt)
524- .done(function(data) {
573+ .done(function (data) {
574+ handleSuccessRequest(url, opt, data);
575+ })
576+ .fail(function (err) {
577+ handleErrorRequest(url, opt, err);
578+ });
579+ }
580+ function executeBackendRequest(title, url, backendUrl, opt) {
581+ save();
582+ $('#modal-title').html(title);
583+ $('#modal-body').html('Loading...');
584+ $('#modal-dialog').modal({ show: true });
585+ $.post(backendUrl, opt)
586+ .done(function (data) {
525587 data.request = opt;
526- if (data.refresh_token) {
527- localStorage.setItem('auth_debugger_refresh_token', data.refresh_token);
528- }
529- if (data.request.password) {
530- data.request.password = '*****************';
531- }
532- if (data.request.client_secret) {
533- data.request.client_secret = '*****************';
534- }
535- $.ajax({ type: "POST", url: '{{baseUrl}}/request', data: JSON.stringify(data), contentType: 'application/json' })
536- .done(function(data) {
537- $('#modal-body').html(data);
538- $('#modal-body').prepend($('<pre/>', { 'class':'json-object', 'html': 'POST ' + url }));
539- })
540- .fail(function(err) {
541- $('#modal-body').html('<p>Error decoding the response.</p>');
542- $('<pre/>', { 'class':'json-object', 'html': err.responseText || err.name || err.text || err.body || err.status }).appendTo('#modal-body');
543- });
588+ handleSuccessRequest(url, opt, data);
544589 })
545- .fail(function(err) {
546- if (opt.password) {
547- opt.password = '*****************';
548- }
549- if (opt.client_secret) {
550- opt.client_secret = '*****************';
551- }
552- $.ajax({ type: "POST", url: '{{baseUrl}}/request', data: JSON.stringify({ request: opt, err: err }), contentType: 'application/json' })
553- .done(function(data) {
554- $('#modal-body').html(data);
555- $('#modal-body').prepend($('<pre/>', { 'class':'json-object', 'html': 'POST ' + url }));
556- })
557- .fail(function(err) {
558- $('#modal-body').html('<p>Error decoding the response.</p>');
559- $('<pre/>', { 'class':'json-object', 'html': err.responseText || err.name || err.text || err.body || err.status }).appendTo('#modal-body');
560- });
590+ .fail(function (err) {
591+ handleErrorRequest(url, opt, err);
561592 });
562593}
594+ function executeTokenExchange(title, opt) {
595+ var url = 'https://' + $('#domain').val() + '/oauth/token';
596+ var backendUrl = '{{baseUrl}}/request/token';
597+ executeBackendRequest(title, url, backendUrl, opt);
598+ }
599+ function executeCodeExchange(title, opt) {
600+ var url = 'https://' + $('#domain').val() + '/oauth/token';
601+ var backendUrl = '{{baseUrl}}/request/code';
602+ executeBackendRequest(title, url, backendUrl, opt);
603+ }
563604if (!window.location.origin) {
564605 window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
565606}
@@ -659,7 +700,7 @@ $(function () {
659700 } else {
660701 opt.client_secret = $('#client_secret').val();
661702 }
662- executeRequest ('OAuth2 - Authorization Code Exchange', 'https://' + $('#domain').val() + '/oauth/token ', opt);
703+ executeCodeExchange ('OAuth2 - Authorization Code Exchange', opt);
663704 });
664705 $('#oauth2_refresh_token_exchange').click(function(e) {
665706 e.preventDefault();
@@ -676,7 +717,7 @@ $(function () {
676717 } else {
677718 opt.client_secret = $('#client_secret').val();
678719 }
679- executeRequest ('OAuth2 - Refresh Token Exchange', 'https://' + $('#domain').val() + '/oauth/token ', opt);
720+ executeTokenExchange ('OAuth2 - Refresh Token Exchange', opt);
680721 });
681722 $('#oauth2_password_grant').click(function(e) {
682723 e.preventDefault();
0 commit comments