api_op_CreateOAuth2Token.go (4674B)
1 // Code generated by smithy-go-codegen DO NOT EDIT. 2 3 package signin 4 5 import ( 6 "context" 7 8 "github.com/aws/aws-sdk-go-v2/service/signin/types" 9 "github.com/aws/smithy-go/middleware" 10 "github.com/aws/smithy-go/ptr" 11 ) 12 13 // CreateOAuth2Token API 14 // 15 // Path: /v1/token Request Method: POST Content-Type: application/json or 16 // application/x-www-form-urlencoded 17 // 18 // This API implements OAuth 2.0 flows for AWS Sign-In CLI clients, supporting 19 // both: 20 // 21 // - Authorization code redemption (grant_type=authorization_code) - NOT 22 // idempotent 23 // - Token refresh (grant_type=refresh_token) - Idempotent within token validity 24 // window 25 // 26 // The operation behavior is determined by the grant_type parameter in the request 27 // body: 28 // 29 // Authorization Code Flow (NOT Idempotent): 30 // 31 // - JSON or form-encoded body with client_id, grant_type=authorization_code, 32 // code, redirect_uri, code_verifier 33 // - Returns access_token, token_type, expires_in, refresh_token, and id_token 34 // - Each authorization code can only be used ONCE for security (prevents replay 35 // attacks) 36 // 37 // Token Refresh Flow (Idempotent): 38 // 39 // - JSON or form-encoded body with client_id, grant_type=refresh_token, 40 // refresh_token 41 // - Returns access_token, token_type, expires_in, and refresh_token (no 42 // id_token) 43 // - Multiple calls with same refresh_token return consistent results within 44 // validity window 45 // 46 // Authentication and authorization: 47 // 48 // - Confidential clients: sigv4 signing required with signin:ExchangeToken 49 // permissions 50 // - CLI clients (public): authn/authz skipped based on client_id & grant_type 51 // 52 // Note: This operation cannot be marked as @idempotent because it handles both 53 // idempotent (token refresh) and non-idempotent (auth code redemption) flows in a 54 // single endpoint. 55 func (c *Client) CreateOAuth2Token(ctx context.Context, params *CreateOAuth2TokenInput, optFns ...func(*Options)) (*CreateOAuth2TokenOutput, error) { 56 if params == nil { 57 params = &CreateOAuth2TokenInput{} 58 } 59 60 result, metadata, err := c.invokeOperation(ctx, "CreateOAuth2Token", params, optFns, c.addOperationCreateOAuth2TokenMiddlewares) 61 if err != nil { 62 return nil, err 63 } 64 65 out := result.(*CreateOAuth2TokenOutput) 66 out.ResultMetadata = metadata 67 return out, nil 68 } 69 70 // Input structure for CreateOAuth2Token operation 71 // 72 // Contains flattened token operation inputs for both authorization code and 73 // refresh token flows. The operation type is determined by the grant_type 74 // parameter in the request body. 75 type CreateOAuth2TokenInput struct { 76 77 // Flattened token operation inputs The specific operation is determined by 78 // grant_type in the request body 79 // 80 // This member is required. 81 TokenInput *types.CreateOAuth2TokenRequestBody 82 83 noSmithyDocumentSerde 84 } 85 86 func (in *CreateOAuth2TokenInput) bindEndpointParams(p *EndpointParameters) { 87 88 p.IsControlPlane = ptr.Bool(false) 89 } 90 91 // Output structure for CreateOAuth2Token operation 92 // 93 // Contains flattened token operation outputs for both authorization code and 94 // refresh token flows. The response content depends on the grant_type from the 95 // original request. 96 type CreateOAuth2TokenOutput struct { 97 98 // Flattened token operation outputs The specific response fields depend on the 99 // grant_type used in the request 100 // 101 // This member is required. 102 TokenOutput *types.CreateOAuth2TokenResponseBody 103 104 // Metadata pertaining to the operation's result. 105 ResultMetadata middleware.Metadata 106 107 noSmithyDocumentSerde 108 } 109 110 func (c *Client) addOperationCreateOAuth2TokenMiddlewares(stack *middleware.Stack, options Options) (err error) { 111 err = stack.Serialize.Add(&awsRestjson1_serializeOpCreateOAuth2Token{}, middleware.After) 112 if err != nil { 113 return err 114 } 115 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpCreateOAuth2Token{}, middleware.After) 116 if err != nil { 117 return err 118 } 119 120 if err = addComputeContentLength(stack); err != nil { 121 return err 122 } 123 if err = addResolveEndpointMiddleware(stack, options); err != nil { 124 return err 125 } 126 if err = addRecordResponseTiming(stack, options); err != nil { 127 return err 128 } 129 if err = addCredentialSource(stack, options); err != nil { 130 return err 131 } 132 if err = addOpCreateOAuth2TokenValidationMiddleware(stack); err != nil { 133 return err 134 } 135 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 136 return err 137 } 138 if err = addResponseErrorMiddleware(stack); err != nil { 139 return err 140 } 141 if err = addRequestResponseLogging(stack, options); err != nil { 142 return err 143 } 144 if err = addDisableHTTPSMiddleware(stack, options); err != nil { 145 return err 146 } 147 if err = addInterceptors(stack, options); err != nil { 148 return err 149 } 150 return nil 151 }