docstr: Get a guest token that can be used for auth in embedded Superset.
  ---
  post:
    summary: Get a guest token
    requestBody:
      description: Parameters for the guest token
      required: true
      content:
        application/json:
          schema: GuestTokenCreateSchema
    responses:
      200:
        description: Result contains the guest token
        content:
          application/json:
            schema:
              type: object
              properties:
                  token:
                    type: string
      401:
        $ref: '#/components/responses/401'
      400:
        $ref: '#/components/responses/400'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Get","a","guest","token","that","can","be","used","for","auth","in","embedded","Superset",".","--","-","post",":","summary",":","Get","a","guest","token","requestBody",":","description",":","Parameters","for","the","guest","token","required",":","true","content",":","application\/json",":","schema",":","GuestTokenCreateSchema","responses",":","200",":","description",":","Result","contains","the","guest","token","content",":","application\/json",":","schema",":","type",":","object","properties",":","token",":","type",":","string","401",":","$","ref",":","'","#","\/components\/responses\/401'","400",":","$","ref",":","'","#","\/components\/responses\/400'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def guest_token(self) -> Response:
      """Get a guest token that can be used for auth in embedded Superset.
      ---
      post:
        summary: Get a guest token
        requestBody:
          description: Parameters for the guest token
          required: true
          content:
            application/json:
              schema: GuestTokenCreateSchema
        responses:
          200:
            description: Result contains the guest token
            content:
              application/json:
                schema:
                  type: object
                  properties:
                      token:
                        type: string
          401:
            $ref: '#/components/responses/401'
          400:
            $ref: '#/components/responses/400'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          body = guest_token_create_schema.load(request.json)
          self.appbuilder.sm.validate_guest_token_resources(
              body["resources"]
          )
  
          # todo validate stuff:
          # make sure username doesn't reference an existing user
          # check rls rules for validity?
          token = self.appbuilder.sm.create_guest_access_token(
              body["user"], body["resources"], body["rls"]
          )
          return self.response(200, token=token)
      except EmbeddedDashboardNotFoundError as error:
          return self.response_400(message=error.message)
      except ValidationError as error:
          return self.response_400(message=error.messages)
  
imports: import logging
  from typing import Any
  from flask import request, Response
  from flask_appbuilder import expose
  from flask_appbuilder.api import safe
  from flask_appbuilder.security.decorators import permission_name, protect
  from flask_wtf.csrf import generate_csrf
  from marshmallow import EXCLUDE, fields, post_load, Schema, ValidationError
  from superset.commands.dashboard.embedded.exceptions import EmbeddedDashboardNotFoundError
  from superset.extensions import event_logger
  from superset.security.guest_token import GuestTokenResourceType
  from superset.views.base_api import BaseSupersetApi, statsd_metrics
label_desc: Use image node_id 2 for calling the SecurityRestApi obj's underlying member method code with example usage: obj.guest_token() and returns: self, self, self