forked from okta/okta-idx-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenroll.go
More file actions
708 lines (651 loc) · 22.5 KB
/
Copy pathenroll.go
File metadata and controls
708 lines (651 loc) · 22.5 KB
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
/**
* Copyright (c) 2021-Present, Okta, Inc.
*
* 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.
*/
package idx
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
)
// EnrollmentResponse is used for the profile enrolment flow. It holds the
// initial IdX context object and the list of the available steps. At the end
// of the successful flow, the only enrollment step will be
// `EnrollmentStepSuccess` and tokens will be available.
type EnrollmentResponse struct {
idxContext *Context
token *Token
availableSteps []EnrollmentStep
authenticators Authenticators
contextualData *ContextualData
}
// UserProfile holds the necessary information to init the enrollment process.
type UserProfile struct {
LastName string `json:"lastName"`
FirstName string `json:"firstName"`
Email string `json:"email"`
}
// InitProfileEnroll starts the enrollment process.
func (c *Client) InitProfileEnroll(ctx context.Context, up *UserProfile) (*EnrollmentResponse, error) {
idxContext, err := c.Interact(ctx)
if err != nil {
return nil, err
}
resp, err := c.introspect(ctx, idxContext.InteractionHandle)
if err != nil {
return nil, err
}
ro, err := resp.remediationOption("select-enroll-profile")
if err != nil {
return nil, err
}
resp, err = ro.proceed(ctx, nil)
if err != nil {
return nil, err
}
ro, err = resp.remediationOption("enroll-profile")
if err != nil {
return nil, err
}
b, _ := json.Marshal(&struct {
UserProfile *UserProfile `json:"userProfile"`
}{UserProfile: up})
resp, err = ro.proceed(ctx, b)
if err != nil {
return nil, err
}
er := &EnrollmentResponse{
idxContext: idxContext,
}
err = er.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
er.setupAuthenticators(resp)
return er, nil
}
// EnrollmentSuccess Determines if the enrollment response represents an enrollment success.
func (r *EnrollmentResponse) EnrollmentSuccess() bool {
if r.HasStep(EnrollmentStepSuccess) && len(r.availableSteps) == 1 {
return true
}
return false
}
// SetNewPassword sets new password for the user.
func (r *EnrollmentResponse) SetNewPassword(ctx context.Context, password string) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepPasswordSetup) {
return r.missingStepError(EnrollmentStepPasswordSetup)
}
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
ro, authID, err := resp.authenticatorOption("select-authenticator-enroll", "Password", true)
if err != nil {
return nil, err
}
authenticator := []byte(`{
"authenticator": {
"id": "` + authID + `"
}
}`)
resp, err = ro.proceed(ctx, authenticator)
if err != nil {
return nil, err
}
ro, err = resp.remediationOption("enroll-authenticator")
if err != nil {
return nil, err
}
credentials := []byte(`{
"credentials": {
"passcode": "` + strings.TrimSpace(password) + `"
}
}`)
resp, err = ro.proceed(ctx, credentials)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// OktaVerifyInit Initiate Okta Verify enrollment
func (r *EnrollmentResponse) OktaVerifyInit(ctx context.Context, option OktaVerifyOption) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepOktaVerifyInit) {
return r.missingStepError(EnrollmentStepOktaVerifyInit)
}
resp, err := enrollOktaVerify(ctx, r.idxContext.InteractionHandle, option)
if err != nil {
return nil, err
}
r.contextualData = resp.CurrentAuthenticator.Value.ContextualData
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
r.appendStep(EnrollmentStepOktaVerifyPoll)
return r, nil
}
// OktaVerifySMSInit Initiate Okta Verify enrollment via SMS message
func (r *EnrollmentResponse) OktaVerifySMSInit(ctx context.Context, destination string) (*EnrollmentResponse, error) {
phoneNumber := []byte(`{"phoneNumber":"` + destination + `"}`)
return r.oktaVerifyMessageInit(ctx, OktaVerifyOptionSms, phoneNumber)
}
// OktaVerifyEmailInit Initiate Okta Verify enrollment via Email message
func (r *EnrollmentResponse) OktaVerifyEmailInit(ctx context.Context, destination string) (*EnrollmentResponse, error) {
email := []byte(`{"email":"` + destination + `"}`)
return r.oktaVerifyMessageInit(ctx, OktaVerifyOptionEmail, email)
}
// oktaVerifyMessageInit Message init encompasses the base functionality for
// Okta Verify for SMS and Email
func (r *EnrollmentResponse) oktaVerifyMessageInit(ctx context.Context, option OktaVerifyOption, proceedData []byte) (*EnrollmentResponse, error) {
// set channel
_, err := r.OktaVerifyInit(ctx, option)
if err != nil {
return nil, err
}
// introspect in order to set up input
if !r.HasStep(EnrollmentStepEnrollmentChannelData) {
return r.missingStepError(EnrollmentStepEnrollmentChannelData)
}
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
// set the remediation data and proceed
ro, err := resp.remediationOption("enrollment-channel-data")
if err != nil {
return nil, err
}
resp, err = ro.proceed(ctx, proceedData)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// OktaVerifyContinuePolling Determines if the client should continue polling for Okta Verify enrollment.
func (r *EnrollmentResponse) OktaVerifyContinuePolling(ctx context.Context) (*EnrollmentResponse, bool, error) {
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, false, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, false, err
}
// Polling should continue if enroll-poll remidation step is present
if r.HasStep(EnrollmentStepOktaVerifyPoll) {
return r, true, nil
}
return r, false, nil
}
// GoogleAuthInit initiates Google Authenticator setup
func (r *EnrollmentResponse) GoogleAuthInit(ctx context.Context) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepGoogleAuthenticatorInit) {
return r.missingStepError(EnrollmentStepGoogleAuthenticatorInit)
}
err := r.enrollAuthenticator(ctx, "Google Authenticator")
if err != nil {
return nil, err
}
r.appendStep(EnrollmentStepGoogleAuthenticatorConfirmation)
return r, nil
}
func (r *EnrollmentResponse) GoogleAuthConfirm(ctx context.Context, code string) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepGoogleAuthenticatorConfirmation) {
return r.missingStepError(EnrollmentStepGoogleAuthenticatorConfirmation)
}
defer func() {
r.contextualData = nil
}()
return r.confirmWithCode(ctx, code)
}
// VerifyEmail sends verification code to the email provided at the first step.
func (r *EnrollmentResponse) VerifyEmail(ctx context.Context) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepEmailVerification) {
return r.missingStepError(EnrollmentStepEmailVerification)
}
resp, err := verifyEmail(ctx, r.idxContext, "select-authenticator-enroll")
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
r.appendStep(EnrollmentStepEmailConfirmation)
return r, nil
}
// ConfirmEmail confirms email address using the provided code.
func (r *EnrollmentResponse) ConfirmEmail(ctx context.Context, code string) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepEmailConfirmation) {
return r.missingStepError(EnrollmentStepEmailConfirmation)
}
return r.confirmWithCode(ctx, code)
}
// PhoneOption represents the method by which the code will be sent to your phone
type PhoneOption string
// PhoneOption constants.
const (
PhoneMethodVoiceCall PhoneOption = "voice"
PhoneMethodSMS PhoneOption = "sms"
)
// OktaVerifyOption is a verify option type.
type OktaVerifyOption string
// OktaVerifyOption constants.
const (
OktaVerifyOptionQRCode OktaVerifyOption = "qrcode"
OktaVerifyOptionEmail OktaVerifyOption = "email"
OktaVerifyOptionSms OktaVerifyOption = "sms"
)
// VerifyPhone sends verification code to the provided phone. Your phone number
// should contain a country code in `+` format e.g. `+11231231234`.
func (r *EnrollmentResponse) VerifyPhone(ctx context.Context, option PhoneOption, phoneNumber string) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepPhoneVerification) {
return r.missingStepError(EnrollmentStepPhoneVerification)
}
resp, err := verifyPhone(ctx, "select-authenticator-enroll", r.idxContext.InteractionHandle, option, phoneNumber)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
r.appendStep(EnrollmentStepPhoneConfirmation)
return r, nil
}
// ConfirmPhone confirms phone number using the provided code.
func (r *EnrollmentResponse) ConfirmPhone(ctx context.Context, code string) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepPhoneConfirmation) {
return r.missingStepError(EnrollmentStepPhoneConfirmation)
}
return r.confirmWithCode(ctx, code)
}
// WebAuthNSetup initiates WebAuthN setup
func (r *EnrollmentResponse) WebAuthNSetup(ctx context.Context) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepWebAuthNSetup) {
return nil, fmt.Errorf("this step is not available, please try one of %s", r.AvailableSteps())
}
err := r.enrollAuthenticator(ctx, "Security Key or Biometric")
if err != nil {
return nil, err
}
r.appendStep(EnrollmentStepWebAuthNVerify)
return r, nil
}
type WebAuthNVerifyCredentials struct {
Attestation string `json:"attestation"`
ClientData string `json:"clientData"`
}
// WebAuthNVerify enrolls user's Security Key or Biometric
func (r *EnrollmentResponse) WebAuthNVerify(ctx context.Context, credentials *WebAuthNVerifyCredentials) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepWebAuthNVerify) {
return nil, fmt.Errorf("this step is not available, please try one of %s", r.AvailableSteps())
}
if credentials == nil {
return nil, errors.New("invalid credentials")
}
resp, err := webAuthNCredentials(ctx, r.idxContext, "enroll-authenticator", credentials)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// Skip represents general step to proceed with no action. It usually appears
// when other steps are optional.
func (r *EnrollmentResponse) Skip(ctx context.Context) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepSkip) {
return r.missingStepError(EnrollmentStepSkip)
}
resp, err := skip(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// Cancel the whole enrollment process.
func (r *EnrollmentResponse) Cancel(ctx context.Context) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepCancel) {
return r.missingStepError(EnrollmentStepCancel)
}
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
resp, err = resp.Cancel(ctx)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// SecurityQuestions represents dict of available security questions. Each key
// represents unique `QuestionKey`, and value represents the human readable
// question.
type SecurityQuestions map[string]string
// SecurityQuestionOptions returns list of available security questions.
func (r *EnrollmentResponse) SecurityQuestionOptions(ctx context.Context) (*EnrollmentResponse, SecurityQuestions, error) {
if !r.HasStep(EnrollmentStepSecurityQuestionOptions) {
resp, err := r.missingStepError(EnrollmentStepSecurityQuestionOptions)
return resp, nil, err
}
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, nil, err
}
ro, authID, err := resp.authenticatorOption("select-authenticator-enroll", "Security Question", true)
if err != nil {
return nil, nil, err
}
authenticator := []byte(`{
"authenticator": {
"id": "` + authID + `"
}
}`)
resp, err = ro.proceed(ctx, authenticator)
if err != nil {
return nil, nil, err
}
m := make(map[string]string)
ro, err = resp.remediationOption("enroll-authenticator")
if err != nil {
return nil, nil, err
}
v, err := ro.value("credentials")
if err != nil {
return nil, nil, err
}
for i := range v.Options {
if v.Options[i].Label == "Choose a security question" {
obj := v.Options[i].Value.(FormOptionsValueObject).Form.Value
for j := range obj {
if obj[j].Name == "questionKey" {
for k := range obj[j].Options {
m[string(obj[j].Options[k].Value.(FormOptionsValueString))] = obj[j].Options[k].Label
}
}
}
}
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, nil, err
}
r.appendStep(EnrollmentStepSecurityQuestionSetup)
m["custom"] = "Create a security question"
return r, m, nil
}
// SecurityQuestion represents security question to be used for the account verification.
// In case when 'questionKey'=='custom' the 'question' field should be non-empty and contain custom
// security question.
type SecurityQuestion struct {
QuestionKey string `json:"questionKey"`
Question string `json:"question"`
Answer string `json:"answer"`
}
// SetupSecurityQuestion sets up the security question.
func (r *EnrollmentResponse) SetupSecurityQuestion(ctx context.Context, sq *SecurityQuestion) (*EnrollmentResponse, error) {
if !r.HasStep(EnrollmentStepSecurityQuestionSetup) {
return r.missingStepError(EnrollmentStepSecurityQuestionSetup)
}
if sq.QuestionKey == "" {
return nil, errors.New("missing security question key")
}
if sq.Answer == "" {
return nil, errors.New("missing answer for the security question key")
}
if sq.QuestionKey == "custom" && sq.Question == "" {
return nil, errors.New("missing custom question")
}
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
ro, err := resp.remediationOption("enroll-authenticator")
if err != nil {
return nil, err
}
credentials, _ := json.Marshal(&struct {
Credentials *SecurityQuestion `json:"credentials"`
}{Credentials: sq})
resp, err = ro.proceed(ctx, credentials)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
// AvailableSteps returns list of steps that can be executed next. In case of
// successful authentication, list will contain only one "SUCCESS" step.
func (r *EnrollmentResponse) AvailableSteps() []EnrollmentStep {
return r.availableSteps
}
// HasStep checks if the provided step is present in the list of available
// steps.
func (r *EnrollmentResponse) HasStep(s EnrollmentStep) bool {
for i := range r.availableSteps {
if r.availableSteps[i] == s {
return true
}
}
return false
}
func (r *EnrollmentResponse) ContextualData() *ContextualData {
return r.contextualData
}
// Authenticators returns the Authenticators.
func (r *EnrollmentResponse) Authenticators() Authenticators {
return r.authenticators
}
// IsAuthenticated returns true in case "SUCCESS" is present in the list of
// available steps.
func (r *EnrollmentResponse) IsAuthenticated() bool {
return r.HasStep(EnrollmentStepSuccess)
}
// Token returns authorization token. This method should be called when there is
// "SUCCESS" step present in the list of available steps.
func (r *EnrollmentResponse) Token() *Token {
return r.token
}
func (r *EnrollmentResponse) WhereAmI(ctx context.Context) (*EnrollmentResponse, error) {
resp, err := idx.introspect(ctx, r.idxContext.InteractionHandle)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
type EnrollmentStep int
// String is a string representation of the enrollment step.
func (s EnrollmentStep) String() string {
v, ok := enrollStepText[s]
if ok {
return v
}
return unknownStep
}
// These codes indicate what method(s) can be called in the next step.
const (
EnrollmentStepEmailVerification EnrollmentStep = iota + 1 // 'VerifyEmail'
EnrollmentStepEmailConfirmation // 'ConfirmEmail'
EnrollmentStepPasswordSetup // 'SetNewPassword'
EnrollmentStepPhoneVerification // 'VerifyPhone'
EnrollmentStepPhoneConfirmation // 'ConfirmPhone'
EnrollmentStepSecurityQuestionOptions // 'SecurityQuestionOptions'
EnrollmentStepSecurityQuestionSetup // 'SetupSecurityQuestion`
EnrollmentStepOktaVerifyInit // `OktaVerifyInit`
EnrollmentStepOktaVerifyPoll // `OktaVerifyPoll`
EnrollmentStepEnrollmentChannelData // `EnrollmentChannelData`
EnrollmentStepGoogleAuthenticatorInit // `GoogleAuthInitialVerify`
EnrollmentStepGoogleAuthenticatorConfirmation // `GoogleAuthConfirm`
EnrollmentStepWebAuthNSetup // `WebAuthNSetup`
EnrollmentStepWebAuthNVerify // `WebAuthNVerify`
EnrollmentStepCancel // 'Cancel'
EnrollmentStepSkip // 'Skip'
EnrollmentStepSuccess // 'Token'
)
var enrollStepText = map[EnrollmentStep]string{
EnrollmentStepEmailVerification: "EMAIL_VERIFICATION",
EnrollmentStepEmailConfirmation: "EMAIL_CONFIRMATION",
EnrollmentStepPasswordSetup: "PASSWORD_SETUP",
EnrollmentStepPhoneVerification: "PHONE_VERIFICATION",
EnrollmentStepPhoneConfirmation: "PHONE_CONFIRMATION",
EnrollmentStepSecurityQuestionOptions: "SECURITY_QUESTION_OPTIONS",
EnrollmentStepSecurityQuestionSetup: "SECURITY_QUESTION_SETUP",
EnrollmentStepOktaVerifyInit: "OKTA_VERIFY_INIT",
EnrollmentStepOktaVerifyPoll: "OKTA_VERIFY_POLL",
EnrollmentStepEnrollmentChannelData: "ENROLLMENT_CHANNEL_DATA",
EnrollmentStepGoogleAuthenticatorInit: "GOOGLE_AUTHENTICATOR_INIT",
EnrollmentStepGoogleAuthenticatorConfirmation: "GOOGLE_AUTHENTICATOR_CONFIRM",
EnrollmentStepWebAuthNSetup: "WEB_AUTHN_SETUP",
EnrollmentStepWebAuthNVerify: "WEB_AUTHN_VERIFY",
EnrollmentStepCancel: "CANCEL",
EnrollmentStepSkip: "SKIP",
EnrollmentStepSuccess: "SUCCESS",
}
func (r *EnrollmentResponse) setupNextStepsLoginSuccess(ctx context.Context, resp *Response) error {
exchangeForm := []byte(`{
"client_secret": "` + idx.ClientSecret() + `",
"code_verifier": "` + r.idxContext.CodeVerifier + `"
}`)
tokens, err := resp.SuccessResponse.exchangeCode(ctx, exchangeForm)
if err != nil {
return err
}
r.token = tokens
r.availableSteps = []EnrollmentStep{EnrollmentStepSuccess}
return nil
}
//nolint:gocyclo
func (r *EnrollmentResponse) setupNextSteps(ctx context.Context, resp *Response) error {
if resp.LoginSuccess() {
return r.setupNextStepsLoginSuccess(ctx, resp)
}
// resets steps
r.availableSteps = []EnrollmentStep{}
if resp.CancelResponse != nil {
r.appendStep(EnrollmentStepCancel)
}
_, _, err := resp.authenticatorOption("select-authenticator-enroll", "Password", false)
if err == nil {
r.appendStep(EnrollmentStepPasswordSetup)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Email", false)
if err == nil {
r.appendStep(EnrollmentStepEmailVerification)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Phone", false)
if err == nil {
r.appendStep(EnrollmentStepPhoneVerification)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Security Question", false)
if err == nil {
r.appendStep(EnrollmentStepSecurityQuestionOptions)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Okta Verify", false)
if err == nil {
r.appendStep(EnrollmentStepOktaVerifyInit)
}
_, err = resp.remediationOption("enroll-poll")
if err == nil {
r.appendStep(EnrollmentStepOktaVerifyPoll)
}
_, err = resp.remediationOption("enrollment-channel-data")
if err == nil {
r.appendStep(EnrollmentStepEnrollmentChannelData)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Google Authenticator", false)
if err == nil {
r.appendStep(EnrollmentStepGoogleAuthenticatorInit)
}
_, _, err = resp.authenticatorOption("select-authenticator-enroll", "Security Key or Biometric", false)
if err == nil {
r.appendStep(EnrollmentStepWebAuthNSetup)
}
_, err = resp.remediationOption("skip")
if err == nil {
r.appendStep(EnrollmentStepSkip)
}
if len(r.availableSteps) == 0 {
return fmt.Errorf("there are no more steps available: %v", resp.Messages.Values)
}
return nil
}
func (r *EnrollmentResponse) setupAuthenticators(resp *Response) {
r.authenticators = resp.Authenticators
}
func (r *EnrollmentResponse) confirmWithCode(ctx context.Context, code string) (*EnrollmentResponse, error) {
resp, err := passcodeAuth(ctx, r.idxContext, "enroll-authenticator", code)
if err != nil {
return nil, err
}
err = r.setupNextSteps(ctx, resp)
if err != nil {
return nil, err
}
return r, nil
}
func (r *EnrollmentResponse) missingStepError(missingStep EnrollmentStep) (*EnrollmentResponse, error) {
steps := ""
for index, step := range r.availableSteps {
if index != 0 {
steps = fmt.Sprintf("%s, ", steps)
}
steps = fmt.Sprintf("%s%q", steps, step)
}
return nil, fmt.Errorf("%q enrollment step is not available, please try one of %s", missingStep, steps)
}
func (r *EnrollmentResponse) appendStep(step EnrollmentStep) {
for _, _step := range r.availableSteps {
if step == _step {
return
}
}
r.availableSteps = append(r.availableSteps, step)
}
func (r *EnrollmentResponse) enrollAuthenticator(ctx context.Context, authenticatorLabel string) error {
resp, err := enrollAuthenticator(ctx, r.idxContext.InteractionHandle, authenticatorLabel)
if err != nil {
return err
}
r.contextualData = resp.CurrentAuthenticator.Value.ContextualData
return r.setupNextSteps(ctx, resp)
}