aboutsummaryrefslogtreecommitdiffstats
path: root/kubernetes/authentication/templates/_utils.tpl
blob: 806f96164afbc0560c0610be64fa63126e423bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
{{/*
# Copyright © 2024 Tata Communication Limited (TCL), Deutsche Telekom AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/}}

{{/*
Renders a value that contains template.
Usage:
{{ include "auth.realm" ( dict "dot" . "realm" .Values.path.to.realm) }}
*/}}
{{- define "auth.realm" -}}
{{- $dot := default . .dot -}}
{{- $realm := (required "'realm' param, set to the specific service, is required." .realm) -}}
realm: {{ $realm.name }}
{{ if $realm.displayName }}displayName: {{ $realm.displayName }}{{ end }}
id: {{ $realm.name }}
accessTokenLifespan: 1900
registrationAllowed: false
resetPasswordAllowed: true
enabled: true
{{ if $realm.themes }}
{{   if $realm.themes.login }}loginTheme: {{ $realm.themes.login }}{{ end }}
{{   if $realm.themes.admin }}adminTheme: {{ $realm.themes.admin }}{{ end }}
{{   if $realm.themes.account }}accountTheme: {{ $realm.themes.account }}{{ end }}
{{   if $realm.themes.email }}emailTheme: {{ $realm.themes.email }}{{ end }}
{{- end }}
{{- if $realm.accessControl }}
{{ include "auth._roles" $realm }}
{{- end }}
{{ include "auth._clients" (dict "dot" $dot "realm" $realm) }}
{{ include "auth._clientScopes" $realm }}
{{ include "auth._defaultClientScopes" $realm }}
{{ include "auth._groups" $realm }}
{{ include "auth._users" $realm }}
{{ include "auth._identity" $realm }}
{{ include "auth._identityMapper" $realm }}
{{ include "auth._smtpServer" $realm }}
{{ include "auth._attributes" (dict "dot" $dot "realm" $realm) }}
{{- end -}}

{{/*
Renders the roles section in a realm.
Usage:
{{ include "auth._roles" ( dict "dot" .Values) }}
*/}}
{{- define "auth._roles" -}}
{{- $realm := default . .dot -}}
roles:
  realm:
    {{- range $index, $role := $realm.accessControl.assignableRoles }}
    - name: "{{ $role.name }}"
      description: "{{ $role.description }}"
      {{- if $role.associatedAccessRoles }}
      composite: true
      composites:
        client:
          {{- range $key, $accessRole := $realm.accessControl.accessRoles }}
          {{ $client := index $realm.clients $key -}}
          {{ $client.clientId }}:
            {{- range $index2, $associatedRole := $role.associatedAccessRoles }}
            - {{ $associatedRole }}
            {{- end }}
          {{- end }}
      {{- else }}
      composite: false
      {{- end }}
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
    {{- end }}
    - name: "user"
      composite: false
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
    - name: "admin"
      composite: false
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
    - name: "offline_access"
      description: "${role_offline-access}"
      composite: false
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
    - name: "uma_authorization"
      description: "${role_uma_authorization}"
      composite: false
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
    - name: "default-roles-{{ $realm.name }}"
      description: "${role_default-roles}"
      composite: true
      composites:
        realm:
          - "offline_access"
          - "uma_authorization"
        client:
          account:
            - "view-profile"
            - "manage-account"
      clientRole: false
      containerId: "{{ $realm.name }}"
      attributes: {}
  {{- if $realm.accessControl.accessRoles }}
  client:
    {{- range $key, $accessRole := $realm.accessControl.accessRoles }}
    {{ $client := index $realm.clients $key -}}
    {{ $client.clientId }}:
    {{- range $index, $role := get $realm.accessControl.accessRoles $key }}
      - name: "{{ $role.name }}"
        description: "Allows to perform {{ $role.methodsAllowed }} operations for {{ $role.name }} component"
        composite: false
        clientRole: false
        containerId: "{{ $client.clientId }}"
        attributes: {}
    {{- end }}
    {{- end }}
  {{- end }}
{{- end }}

{{/*
Renders the clients section in a realm.
Usage:
{{ include "auth._clients" ( dict "dot" . "realm" $realm ) }}
*/}}
{{- define "auth._clients" -}}
{{- $dot := default . .dot -}}
{{- $realm := (required "'realm' param, set to the specific service, is required." .realm) -}}
clients:
  {{- range $index, $client := $realm.clients }}
  - clientId: "{{ $client.clientId }}"
    {{- if $client.name }}
    name: "{{ $client.name }}"
    {{- end }}
    {{- if $client.description }}
    description: "{{ $client.description }}"
    {{- end }}
    {{- if $client.rootUrl }}
    rootUrl: {{ tpl $client.rootUrl $dot }}
    {{- end }}
    {{- if $client.adminUrl }}
    adminUrl: {{ tpl $client.adminUrl $dot }}
    {{- end }}
    {{- if $client.baseUrl }}
    baseUrl: {{ tpl $client.baseUrl $dot }}
    {{- end }}
    surrogateAuthRequired: {{ default false $client.surrogateAuthRequired }}
    enabled: true
    alwaysDisplayInConsole: false
    clientAuthenticatorType: {{ default "client-secret" $client.clientAuthenticatorType }}
    {{- if $client.secret }}
    secret: "{{ $client.secret }}"
    {{- end }}
    {{- if $client.redirectUris }}
    redirectUris:
      {{- range $index2, $url := $client.redirectUris }}
      - {{ tpl $url $dot }}
      {{- end }}
    {{- else }}
    redirectUris: []
    {{- end }}
    {{- if $client.webOrigins }}
    webOrigins:
      {{- range $index3, $web := $client.webOrigins }}
      - {{ $web | quote }}
      {{- end }}
    {{- else }}
    webOrigins: []
    {{- end }}
    notBefore: 0
    bearerOnly: {{ default false $client.bearerOnly }}
    consentRequired: {{ default false $client.consentRequired }}
    standardFlowEnabled: {{ default true $client.standardFlowEnabled }}
    implicitFlowEnabled: {{ default false $client.implicitFlowEnabled }}
    directAccessGrantsEnabled: {{ default true $client.directAccessGrantsEnabled }}
    serviceAccountsEnabled: {{ default false $client.serviceAccountsEnabled }}
    publicClient: {{ default false $client.publicClient }}
    frontchannelLogout: {{ default false $client.frontchannelLogout }}
    protocol: "{{ default "openid-connect" $client.protocol }}"
    {{- if $client.attributes }}
    attributes:
      {{-   range $key,$value := $client.attributes }}
      {{ $key }}: {{ tpl $value $dot }}
      {{-   end }}
    {{- end }}
    authenticationFlowBindingOverrides: {}
    fullScopeAllowed: true
    nodeReRegistrationTimeout: -1
    protocolMappers:
      {{- if $client.protocolMappers }}
      {{- range $index2, $mapper := $client.protocolMappers }}
      - name: {{ $mapper.name }}
        protocol: "openid-connect"
        protocolMapper: {{ $mapper.protocolMapper }}
        consentRequired: false
        config:
          {{ toYaml $mapper.config | nindent 10 }}
      {{- end }}
      {{- end }}
    defaultClientScopes:
      {{- if $client.defaultClientScopes }}
      {{-   range $index2, $scope := $client.defaultClientScopes }}
      - {{ $scope }}
      {{-   end }}
      {{- else }}
      - web-origins
      - profile
      - acr
      - email
      {{- end }}
    optionalClientScopes:
      {{- if $client.optionalClientScopes }}
      {{-   range $index2, $scope := $client.optionalClientScopes }}
      - {{ $scope }}
      {{-   end }}
      {{- else }}
      - address
      - phone
      - offline_access
      - microprofile-jwt
      {{- end }}
  {{- end }}
{{- end }}

{{/*
Renders the defaulDefaultClientScopes section in a realm.
Usage:
{{ include "auth._defaultClientScopes" ( dict "dot" .Values) }}
*/}}
{{- define "auth._defaultClientScopes" -}}
{{- $dot := default . .dot -}}
{{- if $dot.defaultClientScopes }}
defaultDefaultClientScopes:
  {{- range $index, $scope := $dot.defaultClientScopes }}
  - {{ $scope }}
  {{- end }}
{{- end }}
{{- end }}

{{/*
Renders the clientScopes section in a realm.
Usage:
{{ include "auth._clientScopes" ( dict "dot" .Values) }}
*/}}
{{- define "auth._clientScopes" -}}
{{- $dot := default . .dot -}}
clientScopes:
{{- if $dot.additionalClientScopes }}
{{-   range $index, $scope := $dot.additionalClientScopes }}
- name: {{ $scope.name }}
  description: "{{ default "" $scope.description }}"
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'false'
    display.on.consent.screen: 'true'
    gui.order: ''
    consent.screen.text: "${rolesScopeConsentText}"
  protocolMappers:
    {{- if $scope.protocolMappers }}
    {{- range $index2, $mapper := $scope.protocolMappers }}
    - name: {{ $mapper.name }}
      protocol: "openid-connect"
      protocolMapper: {{ $mapper.protocolMapper }}
      consentRequired: false
      config:
        {{ toYaml $mapper.config | nindent 8 }}
    {{- end }}
    {{- end }}

{{-   end }}
{{- end }}
- name: roles
  description: OpenID Connect scope for add user roles to the access token
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'false'
    display.on.consent.screen: 'true'
    consent.screen.text: "${rolesScopeConsentText}"
  protocolMappers:
  - name: audience resolve
    protocol: openid-connect
    protocolMapper: oidc-audience-resolve-mapper
    consentRequired: false
    config: {}
  - name: realm roles
    protocol: openid-connect
    protocolMapper: oidc-usermodel-realm-role-mapper
    consentRequired: false
    config:
      user.attribute: foo
      access.token.claim: 'true'
      claim.name: realm_access.roles
      jsonType.label: String
      multivalued: 'true'
  - name: client roles
    protocol: openid-connect
    protocolMapper: oidc-usermodel-client-role-mapper
    consentRequired: false
    config:
      user.attribute: foo
      access.token.claim: 'true'
      claim.name: resource_access.${client_id}.roles
      jsonType.label: String
      multivalued: 'true'
- name: groups
  description: Membership to a group
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'true'
    gui.order: ''
    consent.screen.text: ''
  protocolMappers:
  - name: groups
    protocol: openid-connect
    protocolMapper: oidc-group-membership-mapper
    consentRequired: false
    config:
      full.path: 'false'
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: groups
      userinfo.token.claim: 'true'
- name: acr
  description: OpenID Connect scope for add acr (authentication context class reference)
    to the token
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'false'
    display.on.consent.screen: 'false'
  protocolMappers:
  - name: acr loa level
    protocol: openid-connect
    protocolMapper: oidc-acr-mapper
    consentRequired: false
    config:
      id.token.claim: 'true'
      access.token.claim: 'true'
- name: profile
  description: 'OpenID Connect built-in scope: profile'
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'true'
    consent.screen.text: "${profileScopeConsentText}"
  protocolMappers:
  - name: profile
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: profile
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: profile
      jsonType.label: String
  - name: given name
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: firstName
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: given_name
      jsonType.label: String
  - name: website
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: website
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: website
      jsonType.label: String
  - name: zoneinfo
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: zoneinfo
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: zoneinfo
      jsonType.label: String
  - name: locale
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: locale
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: locale
      jsonType.label: String
  - name: gender
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: gender
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: gender
      jsonType.label: String
  - name: family name
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: lastName
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: family_name
      jsonType.label: String
  - name: username
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: username
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: preferred_username
      jsonType.label: String
  - name: middle name
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: middleName
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: middle_name
      jsonType.label: String
  - name: birthdate
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: birthdate
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: birthdate
      jsonType.label: String
  - name: updated at
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: updatedAt
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: updated_at
      jsonType.label: long
  - name: full name
    protocol: openid-connect
    protocolMapper: oidc-full-name-mapper
    consentRequired: false
    config:
      id.token.claim: 'true'
      access.token.claim: 'true'
      userinfo.token.claim: 'true'
  - name: nickname
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: nickname
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: nickname
      jsonType.label: String
  - name: picture
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: picture
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: picture
      jsonType.label: String
- name: address
  description: 'OpenID Connect built-in scope: address'
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'true'
    consent.screen.text: "${addressScopeConsentText}"
  protocolMappers:
  - name: address
    protocol: openid-connect
    protocolMapper: oidc-address-mapper
    consentRequired: false
    config:
      user.attribute.formatted: formatted
      user.attribute.country: country
      user.attribute.postal_code: postal_code
      userinfo.token.claim: 'true'
      user.attribute.street: street
      id.token.claim: 'true'
      user.attribute.region: region
      access.token.claim: 'true'
      user.attribute.locality: locality
- name: web-origins
  description: OpenID Connect scope for add allowed web origins to the access token
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'false'
    display.on.consent.screen: 'false'
    consent.screen.text: ''
  protocolMappers:
  - name: allowed web origins
    protocol: openid-connect
    protocolMapper: oidc-allowed-origins-mapper
    consentRequired: false
    config: {}
- name: phone
  description: 'OpenID Connect built-in scope: phone'
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'true'
    consent.screen.text: "${phoneScopeConsentText}"
  protocolMappers:
  - name: phone number verified
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: phoneNumberVerified
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: phone_number_verified
      jsonType.label: boolean
  - name: phone number
    protocol: openid-connect
    protocolMapper: oidc-usermodel-attribute-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: phoneNumber
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: phone_number
      jsonType.label: String
- name: offline_access
  description: 'OpenID Connect built-in scope: offline_access'
  protocol: openid-connect
  attributes:
    consent.screen.text: "${offlineAccessScopeConsentText}"
    display.on.consent.screen: 'true'
- name: role_list
  description: SAML role list
  protocol: saml
  attributes:
    consent.screen.text: "${samlRoleListScopeConsentText}"
    display.on.consent.screen: 'true'
  protocolMappers:
  - name: role list
    protocol: saml
    protocolMapper: saml-role-list-mapper
    consentRequired: false
    config:
      single: 'false'
      attribute.nameformat: Basic
      attribute.name: Role
- name: microprofile-jwt
  description: Microprofile - JWT built-in scope
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'false'
  protocolMappers:
  - name: upn
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: username
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: upn
      jsonType.label: String
  - name: groups
    protocol: openid-connect
    protocolMapper: oidc-usermodel-realm-role-mapper
    consentRequired: false
    config:
      multivalued: 'true'
      user.attribute: foo
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: groups
      jsonType.label: String
- name: email
  description: 'OpenID Connect built-in scope: email'
  protocol: openid-connect
  attributes:
    include.in.token.scope: 'true'
    display.on.consent.screen: 'true'
    consent.screen.text: "${emailScopeConsentText}"
  protocolMappers:
  - name: email
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: email
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: email
      jsonType.label: String
  - name: email verified
    protocol: openid-connect
    protocolMapper: oidc-usermodel-property-mapper
    consentRequired: false
    config:
      userinfo.token.claim: 'true'
      user.attribute: emailVerified
      id.token.claim: 'true'
      access.token.claim: 'true'
      claim.name: email_verified
      jsonType.label: boolean
{{- end }}

{{/*
Renders the groups section in a realm.
Usage:
{{ include "auth._groups" ( dict "dot" .Values) }}
*/}}
{{- define "auth._groups" -}}
{{- $dot := default . .dot -}}
{{- if $dot.groups }}
groups:
{{-   range $index, $group := $dot.groups }}
  - name: "{{ $group.name }}"
    path: "{{ $group.path }}"
    attributes: {}
    {{- if $group.roles }}
    realmRoles:
      {{- range $index2, $groupRole := $group.roles }}
      - "{{ $groupRole }}"
      {{- end }}
    {{- else }}
    realmRoles: []
    {{- end }}
    clientRoles: {}
    subGroups: []
{{-   end }}
{{- else }}
groups: []
{{- end }}
{{- end }}

{{/*
Renders the users section in a realm.
Usage:
{{ include "auth._users" ( dict "dot" .Values) }}
*/}}
{{- define "auth._users" -}}
{{- $dot := default . .dot -}}
{{- if $dot.initialUsers }}
users:
  {{- range $index, $user := $dot.initialUsers }}
  - username: "{{ $user.username }}"
    enabled: true
    totp: false
    email: "{{ default "" $user.email }}"
    emailVerified: "{{ default true $user.emailVerified }}"
    firstName: "{{ default "" $user.firstName }}"
    lastName: "{{ default "" $user.lastName }}"
    {{- if $user.attributes }}
    attributes:
      {{ toYaml $user.attributes | nindent 6 }}
    {{- else }}
    attributes: {}
    {{- end }}
    {{- if $user.password }}
    credentials:
      - type: "password"
        temporary: false
        value: "{{ $user.password }}"
    {{- end }}
    {{- if $user.credentials }}
    credentials:
      {{ toYaml $user.credentials | nindent 6 }}
    {{- end }}
    disableableCredentialTypes: []
    requiredActions: []
    {{- if $user.realmRoles }}
    realmRoles:
      {{- range $index2, $realmRole := $user.realmRoles }}
      - "{{ $realmRole }}"
      {{- end }}
    {{- else }}
    realmRoles: [ "default-roles-{{ $dot.name }}" ]
    {{- end }}
    {{- if $user.clientRoles }}
    clientRoles:
      {{ toYaml $user.clientRoles | nindent 6 }}
    {{- end }}
    notBefore: 0
    groups: {{ $user.groups | toJson  }}
  {{- end }}
{{- end }}
{{- end }}

{{/*
Renders the identityProviders section in a realm.
Usage:
{{ include "auth._identity" ( dict "dot" .Values) }}
*/}}
{{- define "auth._identity" -}}
{{- $dot := default . .dot -}}
{{- if $dot.identityProviders }}
identityProviders:
{{-  range $index, $provider := $dot.identityProviders }}
  - alias: {{ $provider.name }}
    displayName: {{ $provider.displayName }}
    providerId: oidc
    enabled: true
    updateProfileFirstLoginMode: "on"
    trustEmail: true
    storeToken: true
    addReadTokenRoleOnCreate: true
    authenticateByDefault: false
    linkOnly: false
    firstBrokerLoginFlowAlias: "first broker login"
    config:
      {{ toYaml $provider.config | nindent 6 }}
{{-   end }}
{{- end }}
{{- end }}

{{/*
Renders the identityProviderMappers section in a realm.
Usage:
{{ include "auth._identityMapper" ( dict "dot" .Values) }}
*/}}
{{- define "auth._identityMapper" -}}
{{- $dot := default . .dot -}}
{{- if $dot.identityProviderMappers }}
identityProviderMappers:
{{-  range $index, $mapper := $dot.identityProviderMappers }}
  - name: {{ $mapper.name }}
    identityProviderAlias: {{ $mapper.identityProviderAlias }}
    identityProviderMapper: {{ $mapper.identityProviderMapper }}
    config:
      {{ toYaml $mapper.config | nindent 6 }}
{{-   end }}
{{- end }}
{{- end }}

{{/*
Renders the smtpServer section in a realm.
Usage:
{{ include "auth._smtpServer" ( dict "dot" .Values) }}
*/}}
{{- define "auth._smtpServer" -}}
{{- $dot := default . .dot -}}
{{- if $dot.smtpServer }}
smtpServer:
  {{ toYaml $dot.smtpServer | nindent 2 }}
{{- end }}
{{- end }}

{{/*
Renders the attributes section in a realm.
Usage:
{{ include "auth._attributes" ( dict "dot" . "realm" $realm ) }}
*/}}
{{- define "auth._attributes" -}}
{{- $dot := default . .dot -}}
{{- $realm := (required "'realm' param, set to the specific service, is required." .realm) -}}
attributes:
  frontendUrl: {{ tpl $realm.attributes.frontendUrl $dot }}
  acr.loa.map: "{\"ABC\":\"5\"}"
{{- end }}