You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sdk/api/sdkMiddlewareAuth.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
30
30
3.`credentials`_(Object)_: the client credentials for authentication (`clientId`, `clientSecret`)
31
31
4.`scopes`_(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) (default `manage_project:{projectKey}`) to assign to the OAuth token
32
32
5.`fetch`_(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
33
+
6.`timeout`_(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
34
+
7.`getAbortController`_(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
33
35
34
36
#### Usage example
35
37
@@ -50,6 +52,8 @@ const client = createClient({
50
52
51
53
// Optional if not globally available
52
54
fetch,
55
+
timeout:10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
56
+
getAbortController: () =>newAbortController(),
53
57
}),
54
58
],
55
59
})
@@ -69,6 +73,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
69
73
70
74
4.`scopes`_(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) to assign to the OAuth token. _No default scope is sent_
71
75
5.`fetch`_(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
76
+
6.`timeout`_(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
77
+
7.`getAbortController`_(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
72
78
73
79
#### Usage example
74
80
@@ -93,6 +99,8 @@ const client = createClient({
93
99
94
100
// Optional if not globally available
95
101
fetch,
102
+
timeout:10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
103
+
getAbortController: () =>newAbortController(),
96
104
}),
97
105
],
98
106
})
@@ -109,6 +117,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
109
117
3.`credentials`_(Object)_: the client credentials for authentication (`clientId`, `clientSecret`, `anonymousId`)
110
118
4.`scopes`_(Array)_: a list of [scopes](https://docs.commercetools.com/http-api-authorization.html#scopes) (default `manage_project:{projectKey}`) to assign to the OAuth token
111
119
5.`fetch`_(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
120
+
6.`timeout`_(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
121
+
7.`getAbortController`_(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
112
122
113
123
#### Usage example
114
124
@@ -130,6 +140,8 @@ const client = createClient({
130
140
131
141
// Optional if not globally available
132
142
fetch,
143
+
timeout:10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
144
+
getAbortController: () =>newAbortController(),
133
145
}),
134
146
],
135
147
})
@@ -146,6 +158,8 @@ Creates a [middleware](/sdk/Glossary.md#middleware) to handle authentication for
146
158
3.`credentials`_(Object)_: the client credentials for authentication (`clientId`, `clientSecret`)
147
159
4.`refreshToken`_(String)_: refreshToken from the API to use to fetch new token.
148
160
5.`fetch`_(Function)_: A `fetch` implementation which can be e.g. `node-fetch` or `unfetch` but also the native browser `fetch` function. Only needs be be passed if not globally available (e.g. through `isomorphic-fetch`)
161
+
6.`timeout`_(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
162
+
7.`getAbortController`_(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
149
163
150
164
#### Usage example
151
165
@@ -166,6 +180,8 @@ const client = createClient({
166
180
167
181
// Optional if not globally available
168
182
fetch,
183
+
timeout:10000, // timeout the request if it doesn't complete in 10000ms or 10 seconds
184
+
getAbortController: () =>newAbortController(),
169
185
}),
170
186
],
171
187
})
@@ -182,6 +198,10 @@ Creates a [middleware](/sdk/Glossary.md#middleware) that attaches a provided acc
182
198
`options` is an optional _(Object)_, having the following properties:
183
199
184
200
1.`force`_(Boolean)_: if set to true, existing Authorization header (if any) in the request will be overridden with the supplied access token (Default: `true`)
201
+
2.`timeout`_(Number)_: An optional number value (in milliseconds) which specifies when a request should timeout if authentication request fails to complete.
202
+
3.`getAbortController`_(Function)_: An optional abortController class instance that should signal the http-client to abandon the current request instance.
203
+
204
+
**Note**: if timeout is specified, then it's mandatory to also specify the getAbortController property.
0 commit comments