问题
I am attempting to follow instructions inside https://help.rallydev.com/apps/2.0rc3/doc/#!/guide/embedding_apps to utilize a alm-wsapi-read-only API key. I created a simple defect query app using the rally-app-builder. When I am logged out of Rally, I try to view the defect grid using the following syntax in the Chrome browser, where I insert my apiKey in place of "key here":
file:///C:/ProjectWork/RallyGitHub/rally-app-defect-metrics/deploy/App-external.html?apiKey="key here"
When loading this page asks me for my Rally login credentials instead of defaulting to the Rally user embedded in the API key.
Any help on what I am doing incorrectly?
The app code is as follows in this file:
<!DOCTYPE html>
<html>
<head>
<title>DefectMetrics</title>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/2.0rc3/sdk.js"></script>
<script type="text/javascript">
Rally.onReady(function () {
Ext.define("CustomApp",{extend:"Rally.app.App",componentCls:"app",launch:function(){Rally.data.ModelFactory.getModel({type:"Defect",success:function(model){this.grid=this.add({xtype:"rallygrid",model:model,columnCfgs:["FormattedID","Name","State","Owner"],storeConfig:{filters:[{property:"State",operator:"=",value:"Closed"}]}})},scope:this})}});
Rally.launchApp('CustomApp', {
name:"DefectMetrics",
parentRepos:""
});
});
</script>
</head>
<body>
</body>
</html>
回答1:
When accessed through a file:// URL, AppSDK2.0rc3 apps use JSONP:

Which doesn't allow setting an API key in the request header, so you're prompted for credentials through basic auth.
When run through rally-app-builder run
as described in the Embedding Apps help document, you're running through a node.js server, allowing AppSDK2 to use CORS, and the apiKey can be set as needed in the request header to Rally.
Note that rally-app-builder run
will initially bring up:
http://localhost:1337/App-debug.html
in your default browser, which will prompt you for credentials. However, if you manually append your api key to the URL:
http://localhost:1337/App-debug.html?apiKey=_m9XjyrgVQ6
and refresh, the app will render without the need to enter credentials.
来源:https://stackoverflow.com/questions/26289742/embedding-apps-with-api-key