@@ -15,35 +15,36 @@ npm install @azure/servicefabric
1515
1616### How to use
1717
18- #### nodejs - Authentication, client creation and getClusterManifest as an example written in TypeScript.
18+ #### nodejs - client creation and getClusterManifest as an example written in TypeScript.
1919
2020##### Install @azure/ms-rest-nodeauth
2121
2222- Please install minimum version of ` "@azure/ms-rest-nodeauth": "^3.0.0" ` .
23-
2423``` bash
2524npm install @azure/ms-rest-nodeauth@" ^3.0.0"
2625```
2726
2827##### Sample code
2928
30- [ Service Fabric cluster security scenarios] ( https://docs.microsoft.com/azure/service-fabric/service-fabric-cluster-security )
31-
29+ While the below sample uses the interactive login, other authentication options can be found in the [ README.md file of @azure/ms-rest-nodeauth ] ( https://www.npmjs.com/package/@azure/ms-rest-nodeauth ) package
3230``` typescript
33- import { ServiceFabricClient } from " @azure/servicefabric" ;
34- const baseUri = " <ServiceFabricURL>:<connection-port>" ;
35- const client = new ServiceFabricClient ({
36- baseUri
31+ const msRestNodeAuth = require (" @azure/ms-rest-nodeauth" );
32+ const { ServiceFabricClient } = require (" @azure/servicefabric" );
33+ const subscriptionId = process .env [" AZURE_SUBSCRIPTION_ID" ];
34+
35+ msRestNodeAuth .interactiveLogin ().then ((creds ) => {
36+ const client = new ServiceFabricClient (creds , subscriptionId );
37+ const timeout = 1 ;
38+ client .getClusterManifest (timeout ).then ((result ) => {
39+ console .log (" The result is:" );
40+ console .log (result );
41+ });
42+ }).catch ((err ) => {
43+ console .error (err );
3744});
38- client
39- .getClusterManifest ()
40- .then ((result ) => {
41- console .log (result .manifest );
42- })
43- .catch (console .error );
4445```
4546
46- #### browser - Authentication, client creation and getClusterManifest as an example written in JavaScript.
47+ #### browser - Authentication, client creation and getClusterManifest as an example written in JavaScript.
4748
4849##### Install @azure/ms-rest-browserauth
4950
@@ -56,29 +57,35 @@ npm install @azure/ms-rest-browserauth
5657See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.
5758
5859- index.html
59-
6060``` html
6161<!DOCTYPE html>
6262<html lang =" en" >
6363 <head >
6464 <title >@azure/servicefabric sample</title >
6565 <script src =" node_modules/@azure/ms-rest-js/dist/msRest.browser.js" ></script >
66+ <script src =" node_modules/@azure/ms-rest-browserauth/dist/msAuth.js" ></script >
6667 <script src =" node_modules/@azure/servicefabric/dist/servicefabric.js" ></script >
6768 <script type =" text/javascript" >
68- var baseUri = " <ServiceFabricURL>:<connection-port>" ;
69- var client = new Azure.Servicefabric.ServiceFabricClient ({
70- baseUri
69+ const subscriptionId = " <Subscription_Id>" ;
70+ const authManager = new msAuth.AuthManager ({
71+ clientId: " <client id for your Azure AD app>" ,
72+ tenant: " <optional tenant for your organization>"
7173 });
72- client
73- .getClusterManifest ()
74- .then ((result ) => {
74+ authManager .finalizeLogin ().then ((res ) => {
75+ if (! res .isLoggedIn ) {
76+ // may cause redirects
77+ authManager .login ();
78+ }
79+ const client = new Azure.Servicefabric.ServiceFabricClient (res .creds , subscriptionId);
80+ const timeout = 1 ;
81+ client .getClusterManifest (timeout).then ((result ) => {
7582 console .log (" The result is:" );
7683 console .log (result);
77- })
78- .catch ((err ) => {
84+ }).catch ((err ) => {
7985 console .log (" An error occurred:" );
8086 console .error (err);
8187 });
88+ });
8289 </script >
8390 </head >
8491 <body ></body >
0 commit comments