Skip to content

Commit 6e7c763

Browse files
authored
Merge pull request #11 from ibm-bluemix-mobile-services/name-change
add support for AppID as the VCAP name
2 parents 0042657 + c8799b7 commit 6e7c763

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The `options` parameter is optional. If specified, it can contain:
1414

1515
* `cacheSize` The cache size, the default value is 10000;
1616

17-
The MCABackendStrategy is used for a backend application that is deployed on IBM Bluemix. It will validate the `authorization` header from an incoming request against the MCA server url specified in the VCAP_SERVICES variable, where the service name starts with `AdvancedMobileAccess`, for the `appId` extracted from VCAP_APPLICATION.
17+
The MCABackendStrategy is used for a backend application that is deployed on IBM Bluemix. It will validate the `authorization` header from an incoming request against the MCA server url specified in the VCAP_SERVICES variable, where the service name starts with `AppID`, for the `appId` extracted from VCAP_APPLICATION.
1818

1919
### MCAResourceStrategy
2020
```

lib/util/filter-util.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,93 +11,94 @@
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
14-
* limitations under the License.
14+
* limitations under the License.
1515
*/
1616

1717
var imfService;
1818
var applicationId;
1919

2020
var FilterUtil = {};
2121

22-
FilterUtil.getJson = function(jsonData) {
22+
FilterUtil.getJson = function (jsonData) {
2323
var json = jsonData;
2424
if (typeof jsonData == 'string') {
25-
json = JSON.parse(jsonData);
25+
json = JSON.parse (jsonData);
2626
}
2727

2828
return json;
2929
}
3030

31-
FilterUtil.clone = function(object) {
31+
FilterUtil.clone = function (object) {
3232
var cloneObj = {};
3333

34-
if (object) {
35-
for(var prop in object) {
34+
if (object) {
35+
for (var prop in object) {
3636
cloneObj[prop] = object[prop];
3737
}
3838
}
3939
return cloneObj;
4040
}
4141

42-
FilterUtil.getEnvProperty = function(propName,defaultValue) {
42+
FilterUtil.getEnvProperty = function (propName, defaultValue) {
4343
var result = process.env[propName] || defaultValue;
4444
if (result) {
45-
result = result.trim();
45+
result = result.trim ();
4646
}
4747

4848
return result;
4949
}
5050

51-
FilterUtil.getAppIdFromUrl = function(url) {
51+
FilterUtil.getAppIdFromUrl = function (url) {
5252
var result = null;
5353
var reg = /([0-9,a-f]{8}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{12}){1}/ig;
5454
if (url) {
55-
var matches = url.match(reg);
56-
result = matches && matches.length>0 && matches[0];
55+
var matches = url.match (reg);
56+
result = matches && matches.length > 0 && matches[0];
5757
}
5858

5959
return result;
6060
}
6161

62-
FilterUtil.getApplicationIdFromVcap = function() {
63-
if (! applicationId) {
64-
var imfService = getImfService();
62+
FilterUtil.getApplicationIdFromVcap = function () {
63+
if (!applicationId) {
64+
var imfService = getImfService ();
6565
applicationId = imfService && imfService['credentials'] && imfService['credentials']['tenantId'];
6666
}
6767
return applicationId;
6868
}
6969

70-
FilterUtil.getServerUrlFromVcap = function() {
71-
var imfService = getImfService();
70+
FilterUtil.getServerUrlFromVcap = function () {
71+
var imfService = getImfService ();
7272
var serverUrl = imfService && imfService['credentials'] && imfService['credentials']['serverUrl'];
7373

7474
return serverUrl;
7575
}
7676

77-
FilterUtil.getArrayFromString = function(value,delim) {
77+
FilterUtil.getArrayFromString = function (value, delim) {
7878
var array = [];
7979
if (value) {
80-
var a = value.split(delim);
81-
if (a && a.length>0) {
82-
a.forEach(function(item){
83-
array.push(item.trim());
80+
var a = value.split (delim);
81+
if (a && a.length > 0) {
82+
a.forEach (function (item) {
83+
array.push (item.trim ());
8484
});
8585
}
8686
}
8787
return array;
8888
}
8989

90-
FilterUtil.getMcaServiceCredentials = function (){
91-
var mcaServiceInfo = getImfService();
90+
FilterUtil.getMcaServiceCredentials = function () {
91+
var mcaServiceInfo = getImfService ();
9292
var credentials = mcaServiceInfo && mcaServiceInfo["credentials"];
9393
return credentials;
9494
}
9595

96-
function getImfService() {
96+
function getImfService () {
9797
if (!imfService) {
98-
var vcapServices = FilterUtil.getJson(process.env['VCAP_SERVICES']);
98+
var vcapServices = FilterUtil.getJson (process.env['VCAP_SERVICES']);
9999
for (var prop in vcapServices) {
100-
if (prop.indexOf('AdvancedMobileAccess') == 0 && vcapServices[prop].length > 0) {
100+
if (prop.indexOf ('AdvancedMobileAccess') === 0 && vcapServices[prop].length > 0 ||
101+
prop.indexOf ('AppID') === 0 && vcapServices[prop].length > 0) {
101102
imfService = vcapServices[prop][0];
102103
}
103104
}

0 commit comments

Comments
 (0)