0.0.4 • Published 3 years ago

mods-server-sdk-simulator v0.0.4

Weekly downloads
15
License
MIT
Repository
-
Last release
3 years ago

MODS server SDK library

Notice:

MODS server SDK

Usage

run npm install mods-server-sdk at your project

    import { MODS,MODSConfig } from "mods-server-sdk";

API samples:

// Initialize the mods server SDK
let client = new MODS(modsConfig);

// Get basic user info from SSO token
let currentUser = client.getUserInfo();

// Get App Identity Access Token
let tokenResult = await client.getAccessTokenWithAppIdentity("https://graph.microsoft.com");

// Get App Identity Access graph client
let graphClient = await client.getGraphClientWithApplicationPermission();
let profile = await graphClient.api(`/users/` + currentUser.ObjectId).get()

// Call App Identity Access Function
let res = await client.callFunctionWithAppIdentity("httpTrigger", "post", body);

// Get User Identity Access Token
let tokenResult = await client.getAccessTokenWithUserIdentity("https://graph.microsoft.com");

// Get User Identity Access graph client
let graphClient = await client.getMicrosoftGraphClientWithUserIdentity();
let profile = await graphClient.api("/me").get();

// Call User Identity Access Function
let res = await client.callFunctionWithUserIdentity("httpTrigger", "post", body);

Azure SQL samples:

// Initialize the mods server SDK.
let client = new MODS(modsConfig);

// Get conn. Make sure identityId, SqlEndpoint, database in modsConfig is configed
let conn = await client.getSqlConnection()

// 
// user costumized code to use connection to query
//

conn.close()

Before using the Azure SQL samples, user should operate following steps. 1. provision Functions. 2. provision Azure SQL server. 3. config Azure SQL with Active Directory admin. 3. provision Azure SQL database. 4. set firewall policy to allow function access database (Allow Azure services and resources to access) 4. provision a user-assigned managed identity. 6. add identity name to database (use T-SQL command in database CREATE USER [identity name] FROM EXTERNAL PROVIDER;). 7. assign user-assigned managerd identity to the function.