Question

I created a small server in Node.js to handle Rally POST requests. This has been working until I updated to the Rally v2.0 API. With the new authorization model, I'm not sure what I have to do to my server so that I no longer get 'Not authorized to perform action: Invalid Key'. I read the Rally authorization doc but I'm not sure how to apply it within the server. Here's what I have that doesn't work:

var express = require('express');
var app = express();
var sys = require('util');
var client = require('restler');
var userNamePassword = { 'username': 'myusername', 'password': 'mypassword' };
app.use(express.bodyParser());

app.all('/rally/projectpermission/create', function(req, res)
{
  client.get("https://rally.eng.xxxx.com/slm/webservice/v2.0/security/authorize", userNamePassword)
  .on('complete', function(data, response)
  {
    var result = JSON.parse(data);
    var operationResult = result['OperationResult'];
    securityToken = operationResult['SecurityToken'];

    var p = 'https://rally.eng.xxxx.com/slm/webservice/v2.0/projectpermission/create?key=_SECURITY_TOKEN_'.replace('_SECURITY_TOKEN_', securityToken);

    client.postJson(p, req.body, userNamePassword)
    .on('complete', function(data, response)
    {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With");
      res.json(response.statusCode);
    })
    .on('success', function(data, response)
    {
      console.log('success: ' + data);
    })
    .on('fail', function(data, response)
    {
      console.log('fail: ' + data);
    })
    .on('error', function(err, response)
    {
      console.log('error: ' + err);
    });
  });
});

app.listen(3000);
Was it helpful?

Solution

As long as you're including the credentials on the get request to /security/authorize it should work. Are you getting a valid key back?

We have also recently released a Node.js toolkit for working with Rally's WSAPI. It handles all of this authentication for you and also makes a lot of the other operations like querying easier.

Check it out: https://github.com/rallytools/rally-node

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top