Trouble with secured services

Discussion created by RWHupp on Nov 26, 2013
Latest reply on Dec 19, 2013 by kmacleod
We are currently in the process of trying to secure our services in our organization and I am not understanding an error with a secure service I'm working with.
Going thru ArcGIS Server Manager I set the security settings for private and specify roles for the individual service. This of course removes the service from our REST services directory until I log in with my credentials, then I am able to see it. Using the secured service I am able to create a web map in AGOL which of course prompts me for my credentials at which time when entered displays the sercured service on the web map.

My problem or question is that when I use the service in a javascript application it prompts me for authorization but when I enter my credentials it does not allow me access to the secured service through the javascript application. I get an "Unable to access the authentication service". What am I missing? Why can't I access the service through the application?
Here is my code:


      var map, center, zoom, grid;

      function init() {
        center = [-98.495, 29.42];
        zoom = 13;
        map = new esri.Map("map", {
          basemap: "streets",
          center: center,
          zoom: zoom
  var transMapLayer = new esri.layers.ArcGISDynamicMapServiceLayer("", {
          id: "trans",
    minScale: "4500",
    opacity: "0.6"

        var mainMapLayer = new esri.layers.ArcGISDynamicMapServiceLayer("");
        map.addLayers([transMapLayer, mainMapLayer]);
        var legend = new esri.dijit.Legend({
          map: map,
          layerInfos: [{layer:mainMapLayer,title:"ACA Enrollment Assistance"}],
          arrangement: esri.dijit.Legend.ALIGN_RIGHT
        map.on("click", identifyPOI);
        dojo.connect(grid, "onRowClick", onRowClickHandler);
      function identifyPOI(evt){
        var identify = new esri.tasks.IdentifyTask("");
        var identifyParams = new esri.tasks.IdentifyParameters();
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        identifyParams.returnGeometry = true;
        identifyParams.tolerance = 3;
        identify.execute(identifyParams, function(results){
          map.infoWindow.setFeatures(, function(result){
            var feature = result.feature;
            feature.setInfoTemplate(new esri.InfoTemplate( "Name", "<tr>Name:<td>${Name}</tr></td><br><tr>Address:<td>${Address}</tr></td><br><tr>Zip:<td>${ZIP}</tr></td>"));
            return feature;
      function doFind() {
        var findTask = new esri.tasks.FindTask("");
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = [ "Name", "Address", "ZIP"];
        findParams.outSpatialReference = map.spatialReference;
        findParams.searchText = dojo.byId("ownerName").value;

      function showResults(results) {;
        var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 25, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
        var items =,function(result){
          var graphic = result.feature;
          return result.feature.attributes;
        //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items

         //Create data store and bind to grid.
        var store = new{ data:data });
        grid = dijit.byId('grid');

        //Zoom back to the initial map extent
        map.centerAndZoom(center, zoom);

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;
        var distance = 100;

          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic.geometry;
        var newExtent = new esri.geometry.Extent({
          "xmin": selectedTaxLot.x - distance,
          "ymin": selectedTaxLot.y - distance,
          "xmax": selectedTaxLot.x + distance,
          "ymax": selectedTaxLot.y + distance,
          "spatialReference": {
            "wkid": 102100

Here is the error:

Any help or direction would be greatly appreciated!