mods-server-sdk
v0.2.0
Published
Auth library for mods app server side
Downloads
14
Readme
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.
- provision Functions.
- provision Azure SQL server.
- config Azure SQL with Active Directory admin.
- provision Azure SQL database.
- set firewall policy to allow function access database (Allow Azure services and resources to access)
- provision a user-assigned managed identity.
- add identity name to database (use T-SQL command in database
CREATE USER [identity name] FROM EXTERNAL PROVIDER;
). - assign user-assigned managerd identity to the function.