Skip to content

Commit f306cc9

Browse files
authored
fix: add warn log insufficient scope for branding templates export (#1047)
* fix: handle warn insufficient scope error for branding templates export * docs: add branding management section with YAML and directory examples
1 parent 6b6e12e commit f306cc9

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

docs/resource-specific-documentation.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,69 @@ Contents of `reset_email_by_code.json`
368368
"html": "./reset_email_by_code.html"
369369
}
370370
```
371+
372+
## Branding
373+
374+
This resource allows to manage branding within your Auth0 tenant. Auth0 can be customized with a look and feel that aligns with your organization's brand requirements and user expectations. `universal_login` template can be customized (make sure to add `read:custom_domains` scope to export templates).
375+
376+
**YAML Example**
377+
378+
Folder structure when in YAML mode.
379+
380+
```yaml
381+
branding:
382+
colors:
383+
page_background: '#FF4F40'
384+
primary: '#2A2E35'
385+
favicon_url: https://example.com/favicon.png
386+
font:
387+
url: https://example.com/font.woff
388+
logo_url: https://example.com/logo.png
389+
templates:
390+
- template: universal_login
391+
body: ./branding_templates/universal_login.html
392+
```
393+
394+
**Directory Example**
395+
396+
Folder structure when in directory mode.
397+
398+
```json
399+
{
400+
"colors": {
401+
"page_background": "#FF4F40",
402+
"primary": "#2A2E35"
403+
},
404+
"favicon_url": "https://example.com/favicon.png",
405+
"font": {
406+
"url": "https://example.com/font.woff"
407+
},
408+
"logo_url": "https://example.com/logo.png"
409+
}
410+
```
411+
412+
For `universal_login` template `templates/` will be created.
413+
414+
- `templates/universal_login.html`
415+
416+
```html
417+
<!DOCTYPE html>
418+
<html>
419+
<head>
420+
{%- auth0:head -%}
421+
</head>
422+
<body>
423+
{%- auth0:widget -%}
424+
<div>page teamplate</div>
425+
</body>
426+
</html>
427+
```
428+
429+
- `templates/universal_login.json`
430+
431+
```json
432+
{
433+
"template": "universal_login",
434+
"body": "./universal_login.html"
435+
}
436+
```

src/tools/auth0/handlers/branding.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ export default class BrandingHandler extends DefaultHandler {
7373
return branding;
7474
} catch (err) {
7575
log.debug(`Error calling branding API, ${err.message}, status code: ${err.statusCode}`);
76-
if (err.statusCode === 403) return branding;
76+
77+
if (err.statusCode === 403) {
78+
log.warn(
79+
'Insufficient scope the read:custom_domains scope is not set. Branding templates will not be exported.'
80+
);
81+
return branding;
82+
}
83+
7784
if (err.statusCode === 404) return branding;
7885
if (err.statusCode === 501) return branding;
7986
throw err;

test/tools/auth0/handlers/branding.tests.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ describe('#branding handler', () => {
9393
});
9494
});
9595

96+
it('should handle insufficient scope error and not export branding templates', async () => {
97+
const auth0 = {
98+
branding: {
99+
getSettings: () => ({
100+
data: {
101+
logo_url: 'https://example.com/logo.png',
102+
},
103+
}),
104+
getUniversalLoginTemplate: () => ({
105+
body: html,
106+
}),
107+
},
108+
customDomains: {
109+
getAll: () => {
110+
const err = new Error('Insufficient scope');
111+
err.statusCode = 403;
112+
return Promise.reject(err);
113+
},
114+
},
115+
};
116+
117+
const handler = new branding.default({ client: auth0 });
118+
const data = await handler.getType();
119+
expect(data).to.deep.equal({
120+
logo_url: 'https://example.com/logo.png',
121+
});
122+
});
123+
96124
it('should update branding settings without templates if no templates set', (done) => {
97125
const auth0 = {
98126
branding: {

0 commit comments

Comments
 (0)