@azure/msal-node-extensions 1.0.0-alpha.32 → 1.0.0-alpha.34
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.
- package/LICENSE +21 -21
- package/README.md +192 -192
- package/binding.gyp +39 -39
- package/dist/msal-node-extensions.cjs.development.js +4 -4
- package/dist/msal-node-extensions.cjs.development.js.map +1 -1
- package/dist/msal-node-extensions.cjs.production.min.js +1 -1
- package/dist/msal-node-extensions.cjs.production.min.js.map +1 -1
- package/dist/msal-node-extensions.esm.js +4 -4
- package/dist/msal-node-extensions.esm.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/package.json +69 -66
- package/src/Dpapi.ts +12 -12
- package/src/broker/NativeBrokerPlugin.ts +418 -418
- package/src/dpapi-addon/dpapi_addon.h +7 -7
- package/src/dpapi-addon/dpapi_not_supported.cpp +13 -13
- package/src/dpapi-addon/dpapi_win.cpp +106 -106
- package/src/dpapi-addon/main.cpp +30 -30
- package/src/error/NativeAuthError.ts +19 -19
- package/src/error/PersistenceError.ts +101 -101
- package/src/index.ts +17 -17
- package/src/lock/CrossPlatformLock.ts +89 -89
- package/src/lock/CrossPlatformLockOptions.ts +15 -15
- package/src/packageMetadata.ts +3 -3
- package/src/persistence/BasePersistence.ts +43 -43
- package/src/persistence/DataProtectionScope.ts +20 -20
- package/src/persistence/FilePersistence.ts +140 -140
- package/src/persistence/FilePersistenceWithDataProtection.ts +92 -92
- package/src/persistence/IPersistence.ts +17 -17
- package/src/persistence/IPersistenceConfiguration.ts +17 -17
- package/src/persistence/KeychainPersistence.ts +89 -89
- package/src/persistence/LibSecretPersistence.ts +90 -90
- package/src/persistence/PersistenceCachePlugin.ts +106 -106
- package/src/persistence/PersistenceCreator.ts +78 -78
- package/src/utils/Constants.ts +67 -67
- package/src/utils/Environment.ts +101 -101
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
#include <napi.h>
|
|
6
|
-
|
|
7
|
-
Napi::Value ProtectDataCommon(bool protect, const Napi::CallbackInfo& info);
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
#include <napi.h>
|
|
6
|
+
|
|
7
|
+
Napi::Value ProtectDataCommon(bool protect, const Napi::CallbackInfo& info);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#include <napi.h>
|
|
7
|
-
|
|
8
|
-
void ProtectDataCommon(bool protect, const Napi::CallbackInfo& info)
|
|
9
|
-
{
|
|
10
|
-
Napi::Env env = info.Env();
|
|
11
|
-
|
|
12
|
-
throw Napi::Error::New(env, "Data protection API is not available on macOs or Linux");
|
|
13
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
|
|
8
|
+
void ProtectDataCommon(bool protect, const Napi::CallbackInfo& info)
|
|
9
|
+
{
|
|
10
|
+
Napi::Env env = info.Env();
|
|
11
|
+
|
|
12
|
+
throw Napi::Error::New(env, "Data protection API is not available on macOs or Linux");
|
|
13
|
+
}
|
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
// Implementation referenced from https://github.com/bradhugh/node-dpapi
|
|
6
|
-
|
|
7
|
-
#include <napi.h>
|
|
8
|
-
#include <uv.h>
|
|
9
|
-
#include <Windows.h>
|
|
10
|
-
#include <dpapi.h>
|
|
11
|
-
#include <functional>
|
|
12
|
-
#include <iostream>
|
|
13
|
-
#include <string>
|
|
14
|
-
|
|
15
|
-
Napi::Value ProtectDataCommon(bool protect, const Napi::CallbackInfo& info)
|
|
16
|
-
{
|
|
17
|
-
Napi::Env env = info.Env();
|
|
18
|
-
|
|
19
|
-
if (info.Length() != 3) {
|
|
20
|
-
throw Napi::RangeError::New(env, "3 arguments are required");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (info[0].IsNull() ||
|
|
24
|
-
info[0].IsUndefined() ||
|
|
25
|
-
!info[0].IsTypedArray() ||
|
|
26
|
-
info[0].As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array)
|
|
27
|
-
{
|
|
28
|
-
throw Napi::TypeError::New(env, "First argument, data, must be a valid Uint8Array");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!info[1].IsNull() &&
|
|
32
|
-
(!info[1].IsTypedArray() || info[1].As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array))
|
|
33
|
-
{
|
|
34
|
-
throw Napi::TypeError::New(env, "Second argument, optionalEntropy, must be null or an ArrayBuffer");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (info[2].IsNull() || info[2].IsUndefined() || !info[2].IsString())
|
|
38
|
-
{
|
|
39
|
-
throw Napi::TypeError::New(env, "Third argument, scope, must be a string");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
DWORD flags = 0;
|
|
43
|
-
Napi::String strData = info[2].As<Napi::String>();
|
|
44
|
-
std::string scope = strData.Utf8Value();
|
|
45
|
-
if (stricmp(scope.c_str(), "LocalMachine") == 0)
|
|
46
|
-
{
|
|
47
|
-
flags = CRYPTPROTECT_LOCAL_MACHINE;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
auto buffer = info[0].As<Napi::Buffer<char>>().Data();
|
|
51
|
-
auto len = info[0].As<Napi::Buffer<char>>().ElementLength();
|
|
52
|
-
|
|
53
|
-
DATA_BLOB entropyBlob;
|
|
54
|
-
entropyBlob.pbData = nullptr;
|
|
55
|
-
if (!info[1].IsNull())
|
|
56
|
-
{
|
|
57
|
-
entropyBlob.pbData = reinterpret_cast<BYTE*>(info[1].As<Napi::Buffer<char>>().Data());
|
|
58
|
-
entropyBlob.cbData = info[1].As<Napi::Buffer<char>>().ElementLength();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
DATA_BLOB dataIn;
|
|
62
|
-
DATA_BLOB dataOut;
|
|
63
|
-
|
|
64
|
-
// initialize input data
|
|
65
|
-
dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
|
|
66
|
-
dataIn.cbData = len;
|
|
67
|
-
|
|
68
|
-
bool success = false;
|
|
69
|
-
|
|
70
|
-
// Call either Protect or Unprotect based on the flag
|
|
71
|
-
if (protect)
|
|
72
|
-
{
|
|
73
|
-
success = CryptProtectData(
|
|
74
|
-
&dataIn,
|
|
75
|
-
nullptr, // Description string
|
|
76
|
-
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
77
|
-
nullptr, // reserved
|
|
78
|
-
nullptr, // pass null for the prompt structure
|
|
79
|
-
flags, // dwFlags
|
|
80
|
-
&dataOut);
|
|
81
|
-
}
|
|
82
|
-
else
|
|
83
|
-
{
|
|
84
|
-
success = CryptUnprotectData(
|
|
85
|
-
&dataIn,
|
|
86
|
-
nullptr, // Description string
|
|
87
|
-
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
88
|
-
nullptr, // reserved
|
|
89
|
-
nullptr, // pass null for the prompt structure
|
|
90
|
-
flags, // dwFlags
|
|
91
|
-
&dataOut);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!success)
|
|
95
|
-
{
|
|
96
|
-
DWORD errorCode = GetLastError();
|
|
97
|
-
std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
|
|
98
|
-
throw Napi::Error::New(env, &errorMessage[0]);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Copy and free the buffer
|
|
102
|
-
Napi::Buffer<char> returnBuffer = Napi::Buffer<char>::Copy(env, reinterpret_cast<char*>(dataOut.pbData), dataOut.cbData);
|
|
103
|
-
LocalFree(dataOut.pbData);
|
|
104
|
-
|
|
105
|
-
return returnBuffer;
|
|
106
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
// Implementation referenced from https://github.com/bradhugh/node-dpapi
|
|
6
|
+
|
|
7
|
+
#include <napi.h>
|
|
8
|
+
#include <uv.h>
|
|
9
|
+
#include <Windows.h>
|
|
10
|
+
#include <dpapi.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <iostream>
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
Napi::Value ProtectDataCommon(bool protect, const Napi::CallbackInfo& info)
|
|
16
|
+
{
|
|
17
|
+
Napi::Env env = info.Env();
|
|
18
|
+
|
|
19
|
+
if (info.Length() != 3) {
|
|
20
|
+
throw Napi::RangeError::New(env, "3 arguments are required");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (info[0].IsNull() ||
|
|
24
|
+
info[0].IsUndefined() ||
|
|
25
|
+
!info[0].IsTypedArray() ||
|
|
26
|
+
info[0].As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array)
|
|
27
|
+
{
|
|
28
|
+
throw Napi::TypeError::New(env, "First argument, data, must be a valid Uint8Array");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!info[1].IsNull() &&
|
|
32
|
+
(!info[1].IsTypedArray() || info[1].As<Napi::TypedArray>().TypedArrayType() != napi_uint8_array))
|
|
33
|
+
{
|
|
34
|
+
throw Napi::TypeError::New(env, "Second argument, optionalEntropy, must be null or an ArrayBuffer");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (info[2].IsNull() || info[2].IsUndefined() || !info[2].IsString())
|
|
38
|
+
{
|
|
39
|
+
throw Napi::TypeError::New(env, "Third argument, scope, must be a string");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
DWORD flags = 0;
|
|
43
|
+
Napi::String strData = info[2].As<Napi::String>();
|
|
44
|
+
std::string scope = strData.Utf8Value();
|
|
45
|
+
if (stricmp(scope.c_str(), "LocalMachine") == 0)
|
|
46
|
+
{
|
|
47
|
+
flags = CRYPTPROTECT_LOCAL_MACHINE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
auto buffer = info[0].As<Napi::Buffer<char>>().Data();
|
|
51
|
+
auto len = info[0].As<Napi::Buffer<char>>().ElementLength();
|
|
52
|
+
|
|
53
|
+
DATA_BLOB entropyBlob;
|
|
54
|
+
entropyBlob.pbData = nullptr;
|
|
55
|
+
if (!info[1].IsNull())
|
|
56
|
+
{
|
|
57
|
+
entropyBlob.pbData = reinterpret_cast<BYTE*>(info[1].As<Napi::Buffer<char>>().Data());
|
|
58
|
+
entropyBlob.cbData = info[1].As<Napi::Buffer<char>>().ElementLength();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DATA_BLOB dataIn;
|
|
62
|
+
DATA_BLOB dataOut;
|
|
63
|
+
|
|
64
|
+
// initialize input data
|
|
65
|
+
dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
|
|
66
|
+
dataIn.cbData = len;
|
|
67
|
+
|
|
68
|
+
bool success = false;
|
|
69
|
+
|
|
70
|
+
// Call either Protect or Unprotect based on the flag
|
|
71
|
+
if (protect)
|
|
72
|
+
{
|
|
73
|
+
success = CryptProtectData(
|
|
74
|
+
&dataIn,
|
|
75
|
+
nullptr, // Description string
|
|
76
|
+
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
77
|
+
nullptr, // reserved
|
|
78
|
+
nullptr, // pass null for the prompt structure
|
|
79
|
+
flags, // dwFlags
|
|
80
|
+
&dataOut);
|
|
81
|
+
}
|
|
82
|
+
else
|
|
83
|
+
{
|
|
84
|
+
success = CryptUnprotectData(
|
|
85
|
+
&dataIn,
|
|
86
|
+
nullptr, // Description string
|
|
87
|
+
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
88
|
+
nullptr, // reserved
|
|
89
|
+
nullptr, // pass null for the prompt structure
|
|
90
|
+
flags, // dwFlags
|
|
91
|
+
&dataOut);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!success)
|
|
95
|
+
{
|
|
96
|
+
DWORD errorCode = GetLastError();
|
|
97
|
+
std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
|
|
98
|
+
throw Napi::Error::New(env, &errorMessage[0]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Copy and free the buffer
|
|
102
|
+
Napi::Buffer<char> returnBuffer = Napi::Buffer<char>::Copy(env, reinterpret_cast<char*>(dataOut.pbData), dataOut.cbData);
|
|
103
|
+
LocalFree(dataOut.pbData);
|
|
104
|
+
|
|
105
|
+
return returnBuffer;
|
|
106
|
+
}
|
package/src/dpapi-addon/main.cpp
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#include <napi.h>
|
|
7
|
-
#include <uv.h>
|
|
8
|
-
#include "dpapi_addon.h"
|
|
9
|
-
|
|
10
|
-
Napi::Value protectData(const Napi::CallbackInfo& info)
|
|
11
|
-
{
|
|
12
|
-
return ProtectDataCommon(true, info);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
Napi::Value unprotectData(const Napi::CallbackInfo& info)
|
|
16
|
-
{
|
|
17
|
-
return ProtectDataCommon(false, info);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|
21
|
-
exports.Set(Napi::String::New(env, "protectData"),
|
|
22
|
-
Napi::Function::New(env, protectData));
|
|
23
|
-
|
|
24
|
-
exports.Set(Napi::String::New(env, "unprotectData"),
|
|
25
|
-
Napi::Function::New(env, unprotectData));
|
|
26
|
-
|
|
27
|
-
return exports;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
NODE_API_MODULE(dpapi, init)
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <napi.h>
|
|
7
|
+
#include <uv.h>
|
|
8
|
+
#include "dpapi_addon.h"
|
|
9
|
+
|
|
10
|
+
Napi::Value protectData(const Napi::CallbackInfo& info)
|
|
11
|
+
{
|
|
12
|
+
return ProtectDataCommon(true, info);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Napi::Value unprotectData(const Napi::CallbackInfo& info)
|
|
16
|
+
{
|
|
17
|
+
return ProtectDataCommon(false, info);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|
21
|
+
exports.Set(Napi::String::New(env, "protectData"),
|
|
22
|
+
Napi::Function::New(env, protectData));
|
|
23
|
+
|
|
24
|
+
exports.Set(Napi::String::New(env, "unprotectData"),
|
|
25
|
+
Napi::Function::New(env, unprotectData));
|
|
26
|
+
|
|
27
|
+
return exports;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
NODE_API_MODULE(dpapi, init)
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { AuthError } from "@azure/msal-common";
|
|
7
|
-
|
|
8
|
-
export class NativeAuthError extends AuthError {
|
|
9
|
-
public statusCode: number;
|
|
10
|
-
public tag: number;
|
|
11
|
-
|
|
12
|
-
constructor(errorStatus: string, errorContext: string, errorCode: number, errorTag: number) {
|
|
13
|
-
super(errorStatus, errorContext);
|
|
14
|
-
this.name = "NativeAuthError";
|
|
15
|
-
this.statusCode = errorCode;
|
|
16
|
-
this.tag = errorTag;
|
|
17
|
-
Object.setPrototypeOf(this, NativeAuthError.prototype);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { AuthError } from "@azure/msal-common";
|
|
7
|
+
|
|
8
|
+
export class NativeAuthError extends AuthError {
|
|
9
|
+
public statusCode: number;
|
|
10
|
+
public tag: number;
|
|
11
|
+
|
|
12
|
+
constructor(errorStatus: string, errorContext: string, errorCode: number, errorTag: number) {
|
|
13
|
+
super(errorStatus, errorContext);
|
|
14
|
+
this.name = "NativeAuthError";
|
|
15
|
+
this.statusCode = errorCode;
|
|
16
|
+
this.tag = errorTag;
|
|
17
|
+
Object.setPrototypeOf(this, NativeAuthError.prototype);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Error thrown when trying to write MSAL cache to persistence.
|
|
8
|
-
*/
|
|
9
|
-
export class PersistenceError extends Error {
|
|
10
|
-
|
|
11
|
-
// Short string denoting error
|
|
12
|
-
errorCode: string;
|
|
13
|
-
// Detailed description of error
|
|
14
|
-
errorMessage: string;
|
|
15
|
-
|
|
16
|
-
constructor(errorCode: string, errorMessage: string) {
|
|
17
|
-
const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
|
|
18
|
-
super(errorString);
|
|
19
|
-
Object.setPrototypeOf(this, PersistenceError.prototype);
|
|
20
|
-
|
|
21
|
-
this.errorCode = errorCode;
|
|
22
|
-
this.errorMessage = errorMessage;
|
|
23
|
-
this.name = "PersistenceError";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Error thrown when trying to access the file system.
|
|
28
|
-
*/
|
|
29
|
-
static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
|
|
30
|
-
return new PersistenceError(errorCode, errorMessage);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when trying to write, load, or delete data from secret service on linux.
|
|
35
|
-
* Libsecret is used to access secret service.
|
|
36
|
-
*/
|
|
37
|
-
static createLibSecretError(errorMessage: string): PersistenceError {
|
|
38
|
-
return new PersistenceError("GnomeKeyringError", errorMessage);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Error thrown when trying to write, load, or delete data from keychain on macOs.
|
|
43
|
-
*/
|
|
44
|
-
static createKeychainPersistenceError(errorMessage: string): PersistenceError {
|
|
45
|
-
return new PersistenceError("KeychainError", errorMessage);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
|
|
50
|
-
*/
|
|
51
|
-
static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
|
|
52
|
-
return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Error thrown when using the cross platform lock.
|
|
57
|
-
*/
|
|
58
|
-
static createCrossPlatformLockError(errorMessage: string): PersistenceError {
|
|
59
|
-
return new PersistenceError("CrossPlatformLockError", errorMessage);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Throw cache persistence error
|
|
64
|
-
*
|
|
65
|
-
* @param errorMessage string
|
|
66
|
-
* @returns PersistenceError
|
|
67
|
-
*/
|
|
68
|
-
static createCachePersistenceError(errorMessage: string): PersistenceError {
|
|
69
|
-
return new PersistenceError("CachePersistenceError", errorMessage);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Throw unsupported error
|
|
74
|
-
*
|
|
75
|
-
* @param errorMessage string
|
|
76
|
-
* @returns PersistenceError
|
|
77
|
-
*/
|
|
78
|
-
static createNotSupportedError(errorMessage: string): PersistenceError {
|
|
79
|
-
return new PersistenceError("NotSupportedError", errorMessage);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Throw persistence not verified error
|
|
84
|
-
*
|
|
85
|
-
* @param errorMessage string
|
|
86
|
-
* @returns PersistenceError
|
|
87
|
-
*/
|
|
88
|
-
static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
|
|
89
|
-
return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Throw persistence creation validation error
|
|
94
|
-
*
|
|
95
|
-
* @param errorMessage string
|
|
96
|
-
* @returns PersistenceError
|
|
97
|
-
*/
|
|
98
|
-
static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
|
|
99
|
-
return new PersistenceError("PersistenceNotValidatedError", errorMessage);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when trying to write MSAL cache to persistence.
|
|
8
|
+
*/
|
|
9
|
+
export class PersistenceError extends Error {
|
|
10
|
+
|
|
11
|
+
// Short string denoting error
|
|
12
|
+
errorCode: string;
|
|
13
|
+
// Detailed description of error
|
|
14
|
+
errorMessage: string;
|
|
15
|
+
|
|
16
|
+
constructor(errorCode: string, errorMessage: string) {
|
|
17
|
+
const errorString = errorMessage ? `${errorCode}: ${errorMessage}` : errorCode;
|
|
18
|
+
super(errorString);
|
|
19
|
+
Object.setPrototypeOf(this, PersistenceError.prototype);
|
|
20
|
+
|
|
21
|
+
this.errorCode = errorCode;
|
|
22
|
+
this.errorMessage = errorMessage;
|
|
23
|
+
this.name = "PersistenceError";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Error thrown when trying to access the file system.
|
|
28
|
+
*/
|
|
29
|
+
static createFileSystemError(errorCode: string, errorMessage: string): PersistenceError {
|
|
30
|
+
return new PersistenceError(errorCode, errorMessage);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when trying to write, load, or delete data from secret service on linux.
|
|
35
|
+
* Libsecret is used to access secret service.
|
|
36
|
+
*/
|
|
37
|
+
static createLibSecretError(errorMessage: string): PersistenceError {
|
|
38
|
+
return new PersistenceError("GnomeKeyringError", errorMessage);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Error thrown when trying to write, load, or delete data from keychain on macOs.
|
|
43
|
+
*/
|
|
44
|
+
static createKeychainPersistenceError(errorMessage: string): PersistenceError {
|
|
45
|
+
return new PersistenceError("KeychainError", errorMessage);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Error thrown when trying to encrypt or decrypt data using DPAPI on Windows.
|
|
50
|
+
*/
|
|
51
|
+
static createFilePersistenceWithDPAPIError(errorMessage: string): PersistenceError {
|
|
52
|
+
return new PersistenceError("DPAPIEncryptedFileError", errorMessage);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Error thrown when using the cross platform lock.
|
|
57
|
+
*/
|
|
58
|
+
static createCrossPlatformLockError(errorMessage: string): PersistenceError {
|
|
59
|
+
return new PersistenceError("CrossPlatformLockError", errorMessage);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Throw cache persistence error
|
|
64
|
+
*
|
|
65
|
+
* @param errorMessage string
|
|
66
|
+
* @returns PersistenceError
|
|
67
|
+
*/
|
|
68
|
+
static createCachePersistenceError(errorMessage: string): PersistenceError {
|
|
69
|
+
return new PersistenceError("CachePersistenceError", errorMessage);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Throw unsupported error
|
|
74
|
+
*
|
|
75
|
+
* @param errorMessage string
|
|
76
|
+
* @returns PersistenceError
|
|
77
|
+
*/
|
|
78
|
+
static createNotSupportedError(errorMessage: string): PersistenceError {
|
|
79
|
+
return new PersistenceError("NotSupportedError", errorMessage);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Throw persistence not verified error
|
|
84
|
+
*
|
|
85
|
+
* @param errorMessage string
|
|
86
|
+
* @returns PersistenceError
|
|
87
|
+
*/
|
|
88
|
+
static createPersistenceNotVerifiedError(errorMessage: string): PersistenceError {
|
|
89
|
+
return new PersistenceError("PersistenceNotVerifiedError", errorMessage);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Throw persistence creation validation error
|
|
94
|
+
*
|
|
95
|
+
* @param errorMessage string
|
|
96
|
+
* @returns PersistenceError
|
|
97
|
+
*/
|
|
98
|
+
static createPersistenceNotValidatedError(errorMessage: string): PersistenceError {
|
|
99
|
+
return new PersistenceError("PersistenceNotValidatedError", errorMessage);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
|
|
7
|
-
export { FilePersistence } from "./persistence/FilePersistence";
|
|
8
|
-
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
|
|
9
|
-
export { DataProtectionScope } from "./persistence/DataProtectionScope";
|
|
10
|
-
export { KeychainPersistence } from "./persistence/KeychainPersistence";
|
|
11
|
-
export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
|
|
12
|
-
export { IPersistence } from "./persistence/IPersistence";
|
|
13
|
-
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
|
|
14
|
-
export { PersistenceCreator } from "./persistence/PersistenceCreator";
|
|
15
|
-
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
|
|
16
|
-
export { Environment } from "./utils/Environment";
|
|
17
|
-
export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin";
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { PersistenceCachePlugin } from "./persistence/PersistenceCachePlugin";
|
|
7
|
+
export { FilePersistence } from "./persistence/FilePersistence";
|
|
8
|
+
export { FilePersistenceWithDataProtection } from "./persistence/FilePersistenceWithDataProtection";
|
|
9
|
+
export { DataProtectionScope } from "./persistence/DataProtectionScope";
|
|
10
|
+
export { KeychainPersistence } from "./persistence/KeychainPersistence";
|
|
11
|
+
export { LibSecretPersistence } from "./persistence/LibSecretPersistence";
|
|
12
|
+
export { IPersistence } from "./persistence/IPersistence";
|
|
13
|
+
export { CrossPlatformLockOptions } from "./lock/CrossPlatformLockOptions";
|
|
14
|
+
export { PersistenceCreator } from "./persistence/PersistenceCreator";
|
|
15
|
+
export { IPersistenceConfiguration } from "./persistence/IPersistenceConfiguration";
|
|
16
|
+
export { Environment } from "./utils/Environment";
|
|
17
|
+
export { NativeBrokerPlugin } from "./broker/NativeBrokerPlugin";
|