( meta metadata.ConnectionAuthPendingMetadata, challenge func( instruction string, questions KeyboardInteractiveQuestions, ) ( answers KeyboardInteractiveAnswers, err error, ), )
| 45 | } |
| 46 | |
| 47 | func (o *oauth2Client) KeyboardInteractive( |
| 48 | meta metadata.ConnectionAuthPendingMetadata, |
| 49 | challenge func( |
| 50 | instruction string, |
| 51 | questions KeyboardInteractiveQuestions, |
| 52 | ) ( |
| 53 | answers KeyboardInteractiveAnswers, |
| 54 | err error, |
| 55 | ), |
| 56 | ) AuthenticationContext { |
| 57 | ctx := context.TODO() |
| 58 | var err error |
| 59 | if o.provider.SupportsDeviceFlow() { |
| 60 | deviceFlow, err := o.provider.GetDeviceFlow(ctx, meta) |
| 61 | if err == nil { |
| 62 | authorizationURL, userCode, expiration, err := deviceFlow.GetAuthorizationURL(ctx) |
| 63 | if err == nil { |
| 64 | _, err = challenge( |
| 65 | fmt.Sprintf( |
| 66 | "Please click the following link: %s\n\nEnter the following code: %s\n", |
| 67 | authorizationURL, |
| 68 | userCode, |
| 69 | ), |
| 70 | KeyboardInteractiveQuestions{}, |
| 71 | ) |
| 72 | if err != nil { |
| 73 | return &oauth2Context{false, meta.AuthFailed(), err, deviceFlow} |
| 74 | } |
| 75 | verifyContext, cancelFunc := context.WithTimeout(ctx, expiration) |
| 76 | defer cancelFunc() |
| 77 | _, authenticatedMeta, err := deviceFlow.Verify(verifyContext) |
| 78 | // TODO fallback to authorization code flow if the device flow rate limit is exceeded. |
| 79 | if err != nil { |
| 80 | deviceFlow.Deauthorize(ctx) |
| 81 | return &oauth2Context{false, authenticatedMeta, err, deviceFlow} |
| 82 | } else { |
| 83 | return &oauth2Context{true, authenticatedMeta, nil, deviceFlow} |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | if o.provider.SupportsAuthorizationCodeFlow() { |
| 89 | authCodeFlow, err := o.provider.GetAuthorizationCodeFlow(ctx, meta) |
| 90 | if err == nil { |
| 91 | link, err := authCodeFlow.GetAuthorizationURL(ctx) |
| 92 | if err == nil { |
| 93 | answers, err := challenge( |
| 94 | fmt.Sprintf( |
| 95 | "Please click the following link to log in: %s\n\n", |
| 96 | link, |
| 97 | ), |
| 98 | KeyboardInteractiveQuestions{ |
| 99 | KeyboardInteractiveQuestion{ |
| 100 | ID: "code", |
| 101 | Question: "Please paste the received code: ", |
| 102 | EchoResponse: false, |
| 103 | }, |
| 104 | }, |
nothing calls this directly
no test coverage detected