@mindline/sync 1.0.41 → 1.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,6 @@
2
2
  "ExpandedNodes": [
3
3
  ""
4
4
  ],
5
+ "SelectedNode": "\\index.ts",
5
6
  "PreviewInSolutionExplorer": false
6
7
  }
package/.vs/slnx.sqlite CHANGED
Binary file
Binary file
package/index.d.ts CHANGED
@@ -26,6 +26,7 @@ declare module "@mindline/sync" {
26
26
  loginHint: string;
27
27
  scopes: string[];
28
28
  authTS: Date;
29
+ claimsprincipal: string; // claims principal cached at login to allow clearing cache at logout
29
30
  constructor();
30
31
  }
31
32
  // tenant (Azure AD tenant, AD domain, Google workspace)
@@ -104,7 +105,7 @@ declare module "@mindline/sync" {
104
105
  export type TaskType = "initialization" |
105
106
  "authenticate user" |
106
107
  "reload React" |
107
- "PUT access token" |
108
+ "PUT tenant" |
108
109
  "GET tenant details" |
109
110
  "POST config init" |
110
111
  "GET workspaces" |
@@ -221,7 +222,7 @@ declare module "@mindline/sync" {
221
222
  export function groupsGet(instance: IPublicClientApplication, user: User | undefined, groupSearchString: string): Promise<{groups: Group[], error: string}>;
222
223
  export function signIn(user: User, tasks: TaskArray): void;
223
224
  export function signInIncrementally(user: User, scope: string): void;
224
- export function signOut(user: User): void;
225
+ export function signOut(user: User): boolean;
225
226
  export function tenantRelationshipsGetByDomain(loggedInuser: User, tenant: Tenant, instance: IPublicClientApplication, debug: boolean): boolean;
226
227
  export function tenantRelationshipsGetById(user: User, ii: InitInfo, instance: IPublicClientApplication, tasks: TaskArray, debug: boolean): boolean;
227
228
  export function tenantUnauthenticatedLookup(tenant: Tenant, debug: boolean): Promise<boolean>;
package/index.ts CHANGED
@@ -1074,11 +1074,11 @@ export async function groupsGet(instance: IPublicClientApplication, user: User |
1074
1074
  }
1075
1075
  }
1076
1076
  export function signIn(user: User, tasks: TaskArray): void {
1077
+ // SignIn by an admin consents the full set of permissions, unlike Challenge which requires a consented app
1077
1078
  let tenantURL: string = window.location.href;
1078
- tenantURL += "MicrosoftIdentity/Account/Challenge";
1079
+ tenantURL += "MicrosoftIdentity/Account/SignIn";
1079
1080
  let url: URL = new URL(tenantURL);
1080
1081
  url.searchParams.append("redirectUri", window.location.origin);
1081
- url.searchParams.append("scope", "openid offline_access Directory.AccessAsUser.All CrossTenantInformation.ReadBasic.All");
1082
1082
  url.searchParams.append("domainHint", "organizations");
1083
1083
  if (user.oid !== "1") {
1084
1084
  url.searchParams.append("loginHint", user.mail);
@@ -1099,18 +1099,31 @@ export function signInIncrementally(user: User, scope: string): void {
1099
1099
  url.searchParams.append("loginHint", user.mail);
1100
1100
  window.location.assign(url.href);
1101
1101
  }
1102
- export function signOut(user: User): void {
1102
+ export async function signOut(user: User): Promise<boolean>{
1103
1103
  if (user.oid == "1") return;
1104
- // these lines provide more callbacks during logout
1105
- //let tenantURL: string = window.location.href;
1106
- //tenantURL += "MicrosoftIdentity/Account/SignOut";
1107
- // this line takes advantage of our saved loginHint to logout right away, but requires additional cleanup logic
1108
- // https://aaddevsup.azurewebsites.net/2022/03/how-to-logout-of-an-oauth2-application-without-getting-prompted-to-select-a-user/
1109
- let tenantURL: string = "https://login.microsoftonline.com/common/oauth2/logout";
1110
- let url: URL = new URL(tenantURL);
1111
- url.searchParams.append("post_logout_redirect_uri", window.location.origin);
1112
- url.searchParams.append("logout_hint", user.loginHint);
1113
- window.location.assign(url.href);
1104
+ // set logout_hint in the .NET session for streamlined logout
1105
+ let userEndpoint: string = window.location.href;
1106
+ userEndpoint += "user";
1107
+ let url = new URL(userEndpoint);
1108
+ url.searchParams.append("oid", user.oid);
1109
+ url.searchParams.append("tid", user.tid);
1110
+ url.searchParams.append("loginHint", user.loginHint);
1111
+ url.searchParams.append("verb", "LOGOUT");
1112
+ let options = { method: "PATCH" };
1113
+ let userLogoutResponse: Response = await fetch(url.href, options);
1114
+ if (userLogoutResponse.status == 200 && userLogoutResponse.statusText == "OK") {
1115
+ console.log(`Successfully set admin ${user.mail} logout_hint`);
1116
+ }
1117
+ else {
1118
+ console.log(`Failed to set admin ${user.mail} logout_hint`);
1119
+ return;
1120
+ }
1121
+ // start the logout process triggering callbacks during logout
1122
+ // OnRedirectToIdentityProviderForSignOut - this is where we set the logout_hint for user we are trying to logout
1123
+ // OnSignedOutCallbackRedirect - called when the call sucessfully completes
1124
+ let signoutURL: string = window.location.href;
1125
+ signoutURL += "MicrosoftIdentity/Account/SignOut";
1126
+ window.location.assign(signoutURL);
1114
1127
  }
1115
1128
  //tenantRelationshipsGetByDomain - query AAD for associated company name and id
1116
1129
  export async function tenantRelationshipsGetByDomain(loggedInUser: User, tenant: Tenant, instance: IPublicClientApplication, debug: boolean): Promise<boolean> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mindline/sync",
3
3
  "type": "module",
4
- "version": "1.0.41",
4
+ "version": "1.0.42",
5
5
  "types": "index.d.ts",
6
6
  "exports": "./index.ts",
7
7
  "description": "sync is a node.js package encapsulating javscript classes required for configuring Mindline sync service.",
package/tasks.ts CHANGED
@@ -26,7 +26,7 @@ const data: any[] = [
26
26
  },
27
27
  {
28
28
  id: 4,
29
- task: "PUT access token",
29
+ task: "PUT tenant",
30
30
  start: "1970-01-01T00:00:00",
31
31
  end: "1970-01-01T00:00:00",
32
32
  expected: "0:01",