@azure/msal-node-extensions 1.0.0-alpha.2 → 1.0.0-alpha.20
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 +193 -42
- package/binding.gyp +29 -29
- package/dist/error/PersistenceError.d.ts +32 -4
- package/dist/index.d.ts +3 -0
- package/dist/msal-node-extensions.cjs.development.js +615 -849
- 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 +625 -864
- package/dist/msal-node-extensions.esm.js.map +1 -1
- package/dist/persistence/BasePersistence.d.ts +5 -0
- package/dist/persistence/FilePersistence.d.ts +4 -2
- package/dist/persistence/FilePersistenceWithDataProtection.d.ts +3 -1
- package/dist/persistence/IPersistence.d.ts +3 -1
- package/dist/persistence/IPersistenceConfiguration.d.ts +8 -0
- package/dist/persistence/KeychainPersistence.d.ts +3 -1
- package/dist/persistence/LibSecretPersistence.d.ts +3 -1
- package/dist/persistence/PersistenceCachePlugin.d.ts +11 -7
- package/dist/persistence/PersistenceCreator.d.ts +5 -0
- package/dist/utils/Constants.d.ts +31 -0
- package/dist/utils/Environment.d.ts +16 -0
- package/package.json +27 -14
- package/src/dpapi-addon/Dpapi.ts +17 -12
- package/src/dpapi-addon/dpapi_addon.h +6 -6
- package/src/dpapi-addon/dpapi_not_supported.cpp +19 -19
- package/src/dpapi-addon/dpapi_win.cpp +114 -114
- package/src/dpapi-addon/main.cpp +32 -32
- package/src/error/PersistenceError.ts +101 -65
- package/src/index.ts +16 -8
- package/src/lock/CrossPlatformLock.ts +89 -82
- package/src/lock/CrossPlatformLockOptions.ts +15 -15
- package/src/persistence/BasePersistence.ts +41 -0
- package/src/persistence/DataProtectionScope.ts +20 -20
- package/src/persistence/FilePersistence.ts +140 -134
- package/src/persistence/FilePersistenceWithDataProtection.ts +92 -84
- package/src/persistence/IPersistence.ts +17 -15
- package/src/persistence/IPersistenceConfiguration.ts +14 -0
- package/src/persistence/KeychainPersistence.ts +86 -78
- package/src/persistence/LibSecretPersistence.ts +87 -79
- package/src/persistence/PersistenceCachePlugin.ts +106 -96
- package/src/persistence/PersistenceCreator.ts +73 -0
- package/src/utils/Constants.ts +62 -24
- package/src/utils/Environment.ts +99 -0
- package/changelog.md +0 -14
package/src/dpapi-addon/Dpapi.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface DpapiBindings{
|
|
7
|
-
protectData(dataToEncrypt: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array
|
|
8
|
-
unprotectData(encryptData: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export var Dpapi: DpapiBindings = require("bindings")(
|
|
12
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface DpapiBindings{
|
|
7
|
+
protectData(dataToEncrypt: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array
|
|
8
|
+
unprotectData(encryptData: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array
|
|
9
|
+
}
|
|
10
|
+
/* eslint-disable-next-line @typescript-eslint/no-var-requires, no-var, import/no-commonjs */
|
|
11
|
+
export var Dpapi: DpapiBindings = require("bindings")({
|
|
12
|
+
bindings: "dpapi",
|
|
13
|
+
userDefinedTries: [
|
|
14
|
+
["module_root", "node_modules", "@azure", "msal-node-extensions", "build", "Release", "bindings"],
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
export default Dpapi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info);
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info);
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#include <node.h>
|
|
7
|
-
|
|
8
|
-
v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
|
|
9
|
-
{
|
|
10
|
-
return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
|
|
14
|
-
{
|
|
15
|
-
v8::Isolate* isolate = info.GetIsolate();
|
|
16
|
-
|
|
17
|
-
isolate->ThrowException(v8::Exception::Error(
|
|
18
|
-
CreateUtf8String(isolate, "Data protection API is not available on macOs or Linux")));
|
|
19
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <node.h>
|
|
7
|
+
|
|
8
|
+
v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
|
|
9
|
+
{
|
|
10
|
+
return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
|
|
14
|
+
{
|
|
15
|
+
v8::Isolate* isolate = info.GetIsolate();
|
|
16
|
+
|
|
17
|
+
isolate->ThrowException(v8::Exception::Error(
|
|
18
|
+
CreateUtf8String(isolate, "Data protection API is not available on macOs or Linux")));
|
|
19
|
+
}
|
|
@@ -1,114 +1,114 @@
|
|
|
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 <node.h>
|
|
8
|
-
#include <nan.h>
|
|
9
|
-
#include <Windows.h>
|
|
10
|
-
#include <dpapi.h>
|
|
11
|
-
#include <functional>
|
|
12
|
-
#include <iostream>
|
|
13
|
-
#include <string>
|
|
14
|
-
|
|
15
|
-
v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
|
|
16
|
-
{
|
|
17
|
-
return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
|
|
21
|
-
{
|
|
22
|
-
v8::Isolate* isolate = info.GetIsolate();
|
|
23
|
-
|
|
24
|
-
if (info.Length() != 3) {
|
|
25
|
-
isolate->ThrowException(v8::Exception::RangeError(
|
|
26
|
-
CreateUtf8String(isolate, "3 arguments are required")));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (info[0]->IsNullOrUndefined() || !info[0]->IsUint8Array())
|
|
30
|
-
{
|
|
31
|
-
isolate->ThrowException(v8::Exception::TypeError(
|
|
32
|
-
CreateUtf8String(isolate, "First argument, data, must be a valid Uint8Array")));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!info[1]->IsNull() && !info[1]->IsUint8Array())
|
|
36
|
-
{
|
|
37
|
-
isolate->ThrowException(v8::Exception::TypeError(
|
|
38
|
-
CreateUtf8String(isolate, "Second argument, optionalEntropy, must be null or an ArrayBuffer")));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (info[2]->IsNullOrUndefined() || !info[2]->IsString())
|
|
42
|
-
{
|
|
43
|
-
isolate->ThrowException(v8::Exception::TypeError(
|
|
44
|
-
CreateUtf8String(isolate, "Third argument, scope, must be a string")));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
DWORD flags = 0;
|
|
48
|
-
v8::String::Utf8Value strData(isolate, info[2]);
|
|
49
|
-
std::string scope(*strData);
|
|
50
|
-
if (stricmp(scope.c_str(), "LocalMachine") == 0)
|
|
51
|
-
{
|
|
52
|
-
flags = CRYPTPROTECT_LOCAL_MACHINE;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
auto buffer = node::Buffer::Data(info[0]);
|
|
56
|
-
auto len = node::Buffer::Length(info[0]);
|
|
57
|
-
|
|
58
|
-
DATA_BLOB entropyBlob;
|
|
59
|
-
entropyBlob.pbData = nullptr;
|
|
60
|
-
if (!info[1]->IsNull())
|
|
61
|
-
{
|
|
62
|
-
entropyBlob.pbData = reinterpret_cast<BYTE*>(node::Buffer::Data(info[1]));
|
|
63
|
-
entropyBlob.cbData = node::Buffer::Length(info[1]);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
DATA_BLOB dataIn;
|
|
67
|
-
DATA_BLOB dataOut;
|
|
68
|
-
|
|
69
|
-
// initialize input data
|
|
70
|
-
dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
|
|
71
|
-
dataIn.cbData = len;
|
|
72
|
-
|
|
73
|
-
bool success = false;
|
|
74
|
-
|
|
75
|
-
// Call either Protect or Unprotect based on the flag
|
|
76
|
-
if (protect)
|
|
77
|
-
{
|
|
78
|
-
success = CryptProtectData(
|
|
79
|
-
&dataIn,
|
|
80
|
-
nullptr, // Description string
|
|
81
|
-
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
82
|
-
nullptr, // reserved
|
|
83
|
-
nullptr, // pass null for the prompt structure
|
|
84
|
-
flags, // dwFlags
|
|
85
|
-
&dataOut);
|
|
86
|
-
}
|
|
87
|
-
else
|
|
88
|
-
{
|
|
89
|
-
success = CryptUnprotectData(
|
|
90
|
-
&dataIn,
|
|
91
|
-
nullptr, // Description string
|
|
92
|
-
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
93
|
-
nullptr, // reserved
|
|
94
|
-
nullptr, // pass null for the prompt structure
|
|
95
|
-
flags, // dwFlags
|
|
96
|
-
&dataOut);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (!success)
|
|
100
|
-
{
|
|
101
|
-
DWORD errorCode = GetLastError();
|
|
102
|
-
std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
|
|
103
|
-
isolate->ThrowException(v8::Exception::Error(
|
|
104
|
-
CreateUtf8String(isolate, &errorMessage[0])));
|
|
105
|
-
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Copy and free the buffer
|
|
110
|
-
auto returnBuffer = Nan::CopyBuffer(reinterpret_cast<const char*>(dataOut.pbData), dataOut.cbData).ToLocalChecked();
|
|
111
|
-
LocalFree(dataOut.pbData);
|
|
112
|
-
|
|
113
|
-
info.GetReturnValue().Set(returnBuffer);
|
|
114
|
-
}
|
|
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 <node.h>
|
|
8
|
+
#include <nan.h>
|
|
9
|
+
#include <Windows.h>
|
|
10
|
+
#include <dpapi.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <iostream>
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
v8::Local<v8::String> CreateUtf8String(v8::Isolate* isolate, char* strData)
|
|
16
|
+
{
|
|
17
|
+
return v8::String::NewFromUtf8(isolate, strData, v8::NewStringType::kNormal).ToLocalChecked();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void ProtectDataCommon(bool protect, Nan::NAN_METHOD_ARGS_TYPE info)
|
|
21
|
+
{
|
|
22
|
+
v8::Isolate* isolate = info.GetIsolate();
|
|
23
|
+
|
|
24
|
+
if (info.Length() != 3) {
|
|
25
|
+
isolate->ThrowException(v8::Exception::RangeError(
|
|
26
|
+
CreateUtf8String(isolate, "3 arguments are required")));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (info[0]->IsNullOrUndefined() || !info[0]->IsUint8Array())
|
|
30
|
+
{
|
|
31
|
+
isolate->ThrowException(v8::Exception::TypeError(
|
|
32
|
+
CreateUtf8String(isolate, "First argument, data, must be a valid Uint8Array")));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!info[1]->IsNull() && !info[1]->IsUint8Array())
|
|
36
|
+
{
|
|
37
|
+
isolate->ThrowException(v8::Exception::TypeError(
|
|
38
|
+
CreateUtf8String(isolate, "Second argument, optionalEntropy, must be null or an ArrayBuffer")));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (info[2]->IsNullOrUndefined() || !info[2]->IsString())
|
|
42
|
+
{
|
|
43
|
+
isolate->ThrowException(v8::Exception::TypeError(
|
|
44
|
+
CreateUtf8String(isolate, "Third argument, scope, must be a string")));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
DWORD flags = 0;
|
|
48
|
+
v8::String::Utf8Value strData(isolate, info[2]);
|
|
49
|
+
std::string scope(*strData);
|
|
50
|
+
if (stricmp(scope.c_str(), "LocalMachine") == 0)
|
|
51
|
+
{
|
|
52
|
+
flags = CRYPTPROTECT_LOCAL_MACHINE;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
auto buffer = node::Buffer::Data(info[0]);
|
|
56
|
+
auto len = node::Buffer::Length(info[0]);
|
|
57
|
+
|
|
58
|
+
DATA_BLOB entropyBlob;
|
|
59
|
+
entropyBlob.pbData = nullptr;
|
|
60
|
+
if (!info[1]->IsNull())
|
|
61
|
+
{
|
|
62
|
+
entropyBlob.pbData = reinterpret_cast<BYTE*>(node::Buffer::Data(info[1]));
|
|
63
|
+
entropyBlob.cbData = node::Buffer::Length(info[1]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
DATA_BLOB dataIn;
|
|
67
|
+
DATA_BLOB dataOut;
|
|
68
|
+
|
|
69
|
+
// initialize input data
|
|
70
|
+
dataIn.pbData = reinterpret_cast<BYTE*>(buffer);
|
|
71
|
+
dataIn.cbData = len;
|
|
72
|
+
|
|
73
|
+
bool success = false;
|
|
74
|
+
|
|
75
|
+
// Call either Protect or Unprotect based on the flag
|
|
76
|
+
if (protect)
|
|
77
|
+
{
|
|
78
|
+
success = CryptProtectData(
|
|
79
|
+
&dataIn,
|
|
80
|
+
nullptr, // Description string
|
|
81
|
+
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
82
|
+
nullptr, // reserved
|
|
83
|
+
nullptr, // pass null for the prompt structure
|
|
84
|
+
flags, // dwFlags
|
|
85
|
+
&dataOut);
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
{
|
|
89
|
+
success = CryptUnprotectData(
|
|
90
|
+
&dataIn,
|
|
91
|
+
nullptr, // Description string
|
|
92
|
+
entropyBlob.pbData ? &entropyBlob : nullptr,
|
|
93
|
+
nullptr, // reserved
|
|
94
|
+
nullptr, // pass null for the prompt structure
|
|
95
|
+
flags, // dwFlags
|
|
96
|
+
&dataOut);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!success)
|
|
100
|
+
{
|
|
101
|
+
DWORD errorCode = GetLastError();
|
|
102
|
+
std::string errorMessage = std::string("Encryption/Decryption failed. Error code: ") + std::to_string(errorCode);
|
|
103
|
+
isolate->ThrowException(v8::Exception::Error(
|
|
104
|
+
CreateUtf8String(isolate, &errorMessage[0])));
|
|
105
|
+
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Copy and free the buffer
|
|
110
|
+
auto returnBuffer = Nan::CopyBuffer(reinterpret_cast<const char*>(dataOut.pbData), dataOut.cbData).ToLocalChecked();
|
|
111
|
+
LocalFree(dataOut.pbData);
|
|
112
|
+
|
|
113
|
+
info.GetReturnValue().Set(returnBuffer);
|
|
114
|
+
}
|
package/src/dpapi-addon/main.cpp
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
#include <nan.h>
|
|
7
|
-
#include "dpapi_addon.h"
|
|
8
|
-
|
|
9
|
-
NAN_METHOD(protectData)
|
|
10
|
-
{
|
|
11
|
-
ProtectDataCommon(true, info);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
NAN_METHOD(unprotectData)
|
|
15
|
-
{
|
|
16
|
-
ProtectDataCommon(false, info);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
NAN_MODULE_INIT(init)
|
|
20
|
-
{
|
|
21
|
-
Nan::Set(
|
|
22
|
-
target,
|
|
23
|
-
Nan::New<v8::String>("protectData").ToLocalChecked(),
|
|
24
|
-
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(protectData)).ToLocalChecked());
|
|
25
|
-
|
|
26
|
-
Nan::Set(
|
|
27
|
-
target,
|
|
28
|
-
Nan::New<v8::String>("unprotectData").ToLocalChecked(),
|
|
29
|
-
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(unprotectData)).ToLocalChecked());
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
NODE_MODULE(binding, init)
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include <nan.h>
|
|
7
|
+
#include "dpapi_addon.h"
|
|
8
|
+
|
|
9
|
+
NAN_METHOD(protectData)
|
|
10
|
+
{
|
|
11
|
+
ProtectDataCommon(true, info);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
NAN_METHOD(unprotectData)
|
|
15
|
+
{
|
|
16
|
+
ProtectDataCommon(false, info);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
NAN_MODULE_INIT(init)
|
|
20
|
+
{
|
|
21
|
+
Nan::Set(
|
|
22
|
+
target,
|
|
23
|
+
Nan::New<v8::String>("protectData").ToLocalChecked(),
|
|
24
|
+
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(protectData)).ToLocalChecked());
|
|
25
|
+
|
|
26
|
+
Nan::Set(
|
|
27
|
+
target,
|
|
28
|
+
Nan::New<v8::String>("unprotectData").ToLocalChecked(),
|
|
29
|
+
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(unprotectData)).ToLocalChecked());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
NODE_MODULE(binding, init)
|
|
@@ -1,65 +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(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
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";
|