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
**Umbraco Authorized Services** is an Umbraco package designed to reduce the effort needed to integrate third party services that require authentication and authorization via an OAuth flow into Umbraco solutions. It's based on the premise that working with these services requires a fair bit of plumbing code to handle creating an authorized connection. This is necessary before the developer working with the service can get to actually using the provided API to implement the business requirements.
5
+
**Umbraco Authorized Services** is an Umbraco package designed to reduce the effort needed to integrate third party services that require authentication and authorization via an OAuth or API key based flow into Umbraco solutions. It's based on the premise that working with these services requires a fair bit of plumbing code to handle creating an authorized connection. This is necessary before the developer working with the service can get to actually using the provided API to implement the business requirements.
6
6
7
7
Having worked with a few OAuth integrations across different providers, as would be expected, there are quite a few similarities to the flow that needs to be implemented. Steps include:
8
8
9
9
- Redirecting to an authentication endpoint.
10
-
- Handling the response including an authentication code and exchanging it for an access token.
10
+
- Handling the response including an authentication code (or an oauth token and verifier code) and exchanging it for an access token.
11
11
- Securely storing the token.
12
12
- Including the token in API requests.
13
13
- Serializing requests and deserializing the API responses.
14
14
- Handling cases where the token has expired and obtaining a new one via a refresh token.
15
15
16
+
With API key based flows, the process is a little simpler. But you still have to consider secure storage of the key, providing it correctly in API calls and handling serialization tasks.
17
+
16
18
There are though also differences, across request and response structures and variations in the details of the flow itself.
17
19
18
20
The idea of the package is to try to implement a single, best practice implementation of working with OAuth that can be customized, via configuration or code, for particular providers.
@@ -23,7 +25,7 @@ For the solution developer, the Umbraco Authorized Services offers two primary f
23
25
24
26
Firstly there's an tree available in the _Settings_ section of the backoffice, called _Authorized Services_. The tree shows the list of services based on the details provided in configuration.
25
27
26
-
Each tree entry has a management screen where an administrator can authenticate with an app that has been setup with the service. The status of each service, in terms of whether the authentication and authorization flow has been completed and an access token stored, is shown on this screen.
28
+
Each tree entry has a management screen where an administrator can authenticate with an app that has been setup with the service. The status of each service, in terms of whether the authentication and authorization flow has been completed and an access token (or API key) stored, is shown on this screen.
@@ -115,6 +139,18 @@ The value contains the following elements:
115
139
116
140
Provides a friendly name for the service used for identification in the user interface.
117
141
142
+
###### AuthenticationMethod
143
+
144
+
Specifies the type of authentication the service will use, from one of the following available options: `OAuth1`, `OAuth2AuthorizationCode`, `OAuth2ClientCredentials` or `ApiKey`.
145
+
146
+
If no value is provided, it will default to `OAuth2AuthorizationCode`.
147
+
148
+
###### ClientCredentialsProvision
149
+
150
+
Specifies the available options for providing credentials in an `OAuth2` flow: `AuthHeader` or `RequestBody`.
151
+
152
+
This setting is only utilized when the `AuthenticatedMethod` value is configured as `OAuth2ClientCredentials`.
153
+
118
154
###### ApiHost *
119
155
120
156
The host name for the service API that will be called to deliver business functionality. E.g. for Github this is `https://api.github.com`.
@@ -131,6 +167,33 @@ Some providers make available a separately hosted service for handling requests
131
167
132
168
Used, along with `IdentityHost` to construct a URL that the user is redirected to when initiating the authorization of the service via the backoffice. For GitHub, the required value is `/login/oauth/authorize`.
133
169
170
+
###### CanManuallyProvideToken
171
+
172
+
Specifies whether the service supports generating of tokens via the provider's developer portal such that an administrator can manually add one via the backoffice.
173
+
174
+
###### CanManuallyProvideApiKey
175
+
176
+
Specifies whether an administrator can manually add API keys via the backoffice. You might prefer to use this option instead of storing the key in configuration via the `ApiKey` setting.
177
+
178
+
###### CanExchangeToken
179
+
180
+
Specifies whether the access token can be exchanged with a long lived one.
181
+
182
+
###### ExchangeTokenProvision
183
+
184
+
Provides a strongly typed configuration for a setup that allows exchanging an access token.
185
+
186
+
This setting is only utilized when `CanExchangeToken` is set to `true`.
187
+
188
+
The configuration of exchange tokens includes:
189
+
190
+
- `TokenHost`
191
+
- `RequestTokenPath`
192
+
- `TokenGrantType`
193
+
- `RequestRefreshTokenPath`
194
+
- `RefreshTokenGrantType`
195
+
- `ExchangeTokenWhenExpiresWithin`
196
+
134
197
###### AuthorizationUrlRequiresRedirectUrl
135
198
136
199
Some providers require a redirect URL to be provided with the authentication request. For others, instead it's necessary to configure this as part of the registered app. The default value if not provided via configuration is `false`, which is sufficient for the GitHub example.
@@ -143,6 +206,10 @@ Used, along with `TokenHost` to construct a URL used for retrieving access token
143
206
144
207
An enum value that controls how the request to retrieve an access token is formatted. Options are `Querystring` and `FormUrlEncoded`. `Querystring` is the default value and is used for GitHub.
145
208
209
+
###### RequestAuthorizationPath
210
+
211
+
Required in `OAuth1` flows for building the service authorization URL.
212
+
146
213
###### JsonSerializer
147
214
148
215
An enum value that defines the JSON serializer to use when creating requests and deserializing responses. Options are `Default` and `JsonNet` and `SystemTextJson`.
@@ -156,13 +223,23 @@ An enum value that defines the JSON serializer to use when creating requests and
156
223
This flag indicates whether the basic token should be included in the request for access token. If true, a base64 encoding of <clientId>:<clientSecret> will be added to
157
224
the authorization header.
158
225
226
+
###### API Key
227
+
228
+
Specifies the key a service with `AuthenticationMethod` set to `ApiKey` will use for making authorized requests to the API.
229
+
230
+
###### ApiKeyProvision
231
+
232
+
For `ApiKey` authentication methods, options for passing the API key need to be set, by specifying a method: `HttpHeader` or `QueryString` and the name for the key holding the value.
233
+
159
234
###### ClientId *
160
235
161
236
This value will be retrieved from the registered service app.
237
+
For `OAuth1` flows it matches the `consumer key` value from the registered service app.
162
238
163
239
###### ClientSecret *
164
240
165
241
This value will be retrieved from the registered service app. As the name suggests, it should be kept secret and so is probably best not added directly to `appSettings.json` and checked into source control.
242
+
For `OAuth1` flows it matches the `consumer secret` value from the registered service app.
166
243
167
244
###### UseProofKeyForCodeExchange *
168
245
@@ -177,6 +254,9 @@ compare it with the previously sent `code_challenge`.
177
254
178
255
This value will be configured on the service app and retrieved from there. Best practice is to define only the set of permissions that the integration will need. For GitHub, the single scope needed to retrieve details about a repository's contributors is `repo`.
179
256
257
+
###### IncludeScopesInAuthorizationRequest
258
+
Specifies whether the provided scopes should be included in the authorization request body (e.g. `Microsoft`).
259
+
180
260
###### AccessTokenResponseKey
181
261
182
262
The expected key for retrieving an access token from a response. If not provided the default `access_token` is assumed.
@@ -193,6 +273,10 @@ The expected key for retrieving the datetime of token expiry from a response. If
193
273
194
274
An optional sample request can be provided, which can be used to check that an authorized service is functioning as expected from the backoffice. For example, to retrieve the set of contributors to the Umbraco repository hosted at GitHub, this request can be used: `/repos/Umbraco/Umbraco-CMS/contributors`.
195
275
276
+
###### RefreshAccessTokenWhenExpiresWithin
277
+
278
+
Specifies a time interval for expiration of access tokens.
279
+
196
280
### Authorizing a Service
197
281
198
282
With one or more service configured, it will be available from the items within a tree in the _Settings_ section:
@@ -312,6 +396,10 @@ Responsible for creating an HTTP client used for making authorization requests t
312
396
313
397
Responsible for creating a dictionary of parameters provided in the request to retrieve an access token from an authorization code. Implemented by `AuthorizationParametersBuilder`.
314
398
399
+
#### IAuthorizationPayloadBuilder
400
+
401
+
Responsible for generating the authorization payload used between the authorization and access token requests. Implemented by `AuthorizationPayloadBuilder`.
402
+
315
403
#### IAuthorizationRequestSender
316
404
317
405
Responsible for sending the request to retrieve access tokens. Implemented by `AuthorizationRequestSender`, which depends on `IAuthorizationClientFactory`.
@@ -328,6 +416,10 @@ Responsible for building the URL used to instigate the authentication and author
328
416
329
417
Responsible for creating a request to an authorized service, providing the content and access token. Implemented by `AuthorizedRequestBuilder`.
330
418
419
+
#### IExchangeTokenParametersBuilder
420
+
421
+
Responsible for defining the operations building the dictionary of parameters used in exchange token authorization requests. Implemented by `ExchangeTokenParametersBuilder`.
422
+
331
423
#### IAuthorizedServiceCaller
332
424
333
425
Responsible for making requests to the authorized services for the purposes of accessing business functionality. This is used by Umbraco solution developers and is described in detail above. Implemented by `AuthorizedServiceCaller`.
Responsible for generating the authorization payload used between the authorization and access token requests. Implemented by `AuthorizedServiceAuthorizationPayloadBuilder`.
457
+
Responsible for storing tokens. Implemented by `InMemoryTokenStorage`, `DatabaseOAuth1TokenStorage` and `DatabaseOAuth2TokenStorage`.
0 commit comments