-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow overriding default allowedRoles #60
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,4 +136,69 @@ export default { | |
}) | ||
} | ||
}; | ||
``` | ||
``` | ||
|
||
### allowedRoles | ||
|
||
An array of strings containing the roles allowed to access the app. For e.g. if the app needs to be restrictied it's possible to use a [custom role](https://docs.microsoft.com/en-us/azure/static-web-apps/authentication-authorization). *Notice* this only supports securing the complete app. If specific routes should be secured it's best to implement custom authentication within the app itself. | ||
|
||
```js | ||
export default { | ||
kit: { | ||
... | ||
adapter: azure({ | ||
allowedRoles: ['authenticated'], | ||
customStaticWebAppConfig: { | ||
routes: [ | ||
{ | ||
route: "/.auth/login/facebook", | ||
statusCode: 404 | ||
}, | ||
{ | ||
route: "/.auth/login/github", | ||
statusCode: 404 | ||
}, | ||
{ | ||
route: "/.auth/login/google", | ||
statusCode: 404 | ||
}, | ||
{ | ||
route: "/.auth/login/twitter", | ||
statusCode: 404 | ||
}, | ||
{ | ||
route: "/.auth/*", | ||
allowedRoles: [ | ||
"anonymous" | ||
] | ||
}, | ||
{ | ||
route: '/login', | ||
allowedRoles: [ | ||
"anonymous" | ||
], | ||
rewrite: "/.auth/login/aad", | ||
} | ||
], | ||
responseOverrides: { | ||
'401': { | ||
'redirect': '/login', | ||
'statusCode': 302 | ||
} | ||
}, | ||
auth: { | ||
identityProviders: { | ||
azureActiveDirectory: { | ||
registration: { | ||
openIdIssuer: "AAD_ISSUER", | ||
clientIdSettingName: "AAD_CLIENT_ID", | ||
clientSecretSettingName: "AAD_CLIENT_SECRET" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+151
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this entire config in the docs? Can we just show setting |
||
}) | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,7 +28,8 @@ function validateCustomConfig(config) { | |||||
export default function ({ | ||||||
debug = false, | ||||||
customStaticWebAppConfig = {}, | ||||||
esbuildOptions = {} | ||||||
esbuildOptions = {}, | ||||||
allowedRoles = ['anonymous'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the default should be undefined:
Suggested change
|
||||||
} = {}) { | ||||||
return { | ||||||
name: 'adapter-azure-swa', | ||||||
|
@@ -48,13 +49,15 @@ export default function ({ | |||||
{ | ||||||
route: '*', | ||||||
methods: ['POST', 'PUT', 'DELETE'], | ||||||
rewrite: ssrFunctionRoute | ||||||
rewrite: ssrFunctionRoute, | ||||||
allowedRoles: allowedRoles | ||||||
}, | ||||||
{ | ||||||
route: `/${builder.config.kit.appDir}/immutable/*`, | ||||||
headers: { | ||||||
'cache-control': 'public, immutable, max-age=31536000' | ||||||
} | ||||||
}, | ||||||
allowedRoles: allowedRoles | ||||||
} | ||||||
], | ||||||
navigationFallback: { | ||||||
|
@@ -130,15 +133,24 @@ export default function ({ | |||||
swaConfig.routes.push( | ||||||
{ | ||||||
route: '/index.html', | ||||||
rewrite: ssrFunctionRoute | ||||||
rewrite: ssrFunctionRoute, | ||||||
allowedRoles: allowedRoles | ||||||
}, | ||||||
{ | ||||||
route: '/', | ||||||
rewrite: ssrFunctionRoute | ||||||
rewrite: ssrFunctionRoute, | ||||||
allowedRoles: allowedRoles | ||||||
} | ||||||
); | ||||||
} | ||||||
|
||||||
swaConfig.routes.push( | ||||||
{ | ||||||
route: '*', | ||||||
allowedRoles: allowedRoles | ||||||
} | ||||||
); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of remembering to set swaConfig.routes = swaConfig.routes.map((r) => ({ ...r, allowedRoles })); |
||||||
writeFileSync(`${publish}/staticwebapp.config.json`, JSON.stringify(swaConfig)); | ||||||
} | ||||||
}; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be better to link docs on role configuration instead of the general auth docs: