Skip to contents

as_security_scheme() turns an existing object into a security_scheme object. It uses the type element of such objects to determine which type of security scheme to construct.

Usage

as_security_scheme(x, ...)

Arguments

x

The object to coerce. Must be empty or be a named list, with at least an element type. The type element is processed through snakecase::to_snake_case(), and then must be one of "api_key", "oauth2", or "oauth_2".

...

These dots are for future extensions and must be empty.

Value

A security_scheme object as returned by class_api_key_security_scheme() or class_oauth2_security_scheme().

Examples

as_security_scheme(
  list(
    description = "Account JWT token",
    flows = list(
      password = list(
        scopes = list(
          Catalog = "Access all read-only content",
          Commerce = "Perform account-level transactions",
          Playback = "Allow playback of restricted content",
          Settings = "Modify account settings"
        ),
        tokenUrl = "/account/authorization"
      )
    ),
    type = "oauth2"
  )
)
#> <rapid::oauth2_security_scheme>
#>  @ implicit_flow          : <rapid::oauth2_implicit_flow>
#>  .. @ refresh_url      : chr(0) 
#>  .. @ scopes           : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ authorization_url: chr(0) 
#>  @ password_flow          : <rapid::oauth2_token_flow>
#>  .. @ refresh_url: chr(0) 
#>  .. @ scopes     : <rapid::scopes>
#>  .. .. @ name       : chr [1:4] "Catalog" "Commerce" "Playback" "Settings"
#>  .. .. @ description: chr [1:4] "Access all read-only content" ...
#>  .. @ token_url  : chr "/account/authorization"
#>  @ client_credentials_flow: <rapid::oauth2_token_flow>
#>  .. @ refresh_url: chr(0) 
#>  .. @ scopes     : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ token_url  : chr(0) 
#>  @ authorization_code_flow: <rapid::oauth2_authorization_code_flow>
#>  .. @ refresh_url      : chr(0) 
#>  .. @ scopes           : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ authorization_url: chr(0) 
#>  .. @ token_url        : chr(0) 
as_security_scheme(
  list(
    description = "Profile JWT token",
    flows = list(
      password = list(
        scopes = list(
          Catalog = "Modify profile preferences and activity"
        ),
        tokenUrl = "/account/profile/authorization"
      )
    ),
    type = "oauth2"
  )
)
#> <rapid::oauth2_security_scheme>
#>  @ implicit_flow          : <rapid::oauth2_implicit_flow>
#>  .. @ refresh_url      : chr(0) 
#>  .. @ scopes           : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ authorization_url: chr(0) 
#>  @ password_flow          : <rapid::oauth2_token_flow>
#>  .. @ refresh_url: chr(0) 
#>  .. @ scopes     : <rapid::scopes>
#>  .. .. @ name       : chr "Catalog"
#>  .. .. @ description: chr "Modify profile preferences and activity"
#>  .. @ token_url  : chr "/account/profile/authorization"
#>  @ client_credentials_flow: <rapid::oauth2_token_flow>
#>  .. @ refresh_url: chr(0) 
#>  .. @ scopes     : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ token_url  : chr(0) 
#>  @ authorization_code_flow: <rapid::oauth2_authorization_code_flow>
#>  .. @ refresh_url      : chr(0) 
#>  .. @ scopes           : <rapid::scopes>
#>  .. .. @ name       : chr(0) 
#>  .. .. @ description: chr(0) 
#>  .. @ authorization_url: chr(0) 
#>  .. @ token_url        : chr(0) 
as_security_scheme(
  list(
    `in` = "header",
    name = "authorization",
    type = "apiKey"
  )
)
#> <rapid::api_key_security_scheme>
#>  @ parameter_name: chr "authorization"
#>  @ location      : chr "header"