Some endpoints in ASP.NET Core 8.0 OpenAPI Swagger don’t have authentication

I’m developing an ASP.NET Core 8.0 Web API. Could you tell me why some endpoints don’t have a padlock icon in Swagger UI?

For example, my ASP.NET localhost: localhost ASP.NET swagger.

On the other hand, preview at editor.swagger.io is correct: editor.swagger.io preview.

When I’m executing request (e.g. to /authorize path), request header hasn’t Authentication field.

Second problem, in my opinion related to first one, is that after click on the padlock, I get all authentication options.

For example, I click on GET /student endpoint and I’ll get this: all options authorizations at localhost. In the editor.swagger.io I’ll get one, proper option: one option authorization at editor.swagger.io.

That’s my openapi.yaml:

openapi: 3.0.3
info:
  title: API schema for research project
  description: API schema for research project
  version: 1.0.0
servers:
  - url: 'localhost'
tags:
  - name: general
  - name: student
    description: Access to student data.
paths:
  /hello:
    get:
      tags:
        - general
      summary: Returns "Hello World!" phrase
      description: Returns "Hello World!" phrase.
      responses:
        '200':
          description: successful operation
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/HelloWorld'
  /authorize:
    post:
      tags:
        - general
      summary: Get authorization JWT token
      description: Returns JWT token for further authorization.
      responses:
        '200':
          description: successful operation
          content:
            text/plain:
              schema:
                $ref: '#/components/schemas/JwtToken'
        '401':
          description: unauthorized
      security:
        - jwt_token_auth: []
  /student:
    get:
      tags:
        - student
      summary: Find first n students
      description: Find and return first n students ordered by its IDs.
      parameters:
        - name: results
          in: query
          description: Number of students to return.
          schema:
            type: integer
            default: 1
            minimum: 1
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Student'
        '400':
          description: Invalid 'results' parameter value
        '401':
          description: unauthorized
      security:
        - student_data_auth: []
    post:
      tags:
        - student
      summary: Add a new students
      description: Add a new students
      requestBody:
        description: Create a new students
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/Student'
        required: true
      responses:
        '201':
          description: Created successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Student'
        '400':
          description: Invalid input
        '401':
          description: unauthorized
        '422':
          description: Validation exception
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ErrorMessage'
      security:
        - student_data_auth: []
  /student/{studentId}:
    put:
      tags:
        - student
      summary: Update student
      description: Update student by given ID.
      parameters:
        - name: studentId
          in: path
          description: ID of the student to update
          required: true
          schema:
            type: integer
      requestBody:
        description: Update existing student
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Student'
        required: true
      responses:
        '200':
          description: Updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Student'
        '400':
          description: Invalid input
        '401':
          description: unauthorized
        '404':
          description: Student not found
        '422':
          description: Validation exception
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ErrorMessage'
      security:
        - student_data_auth: []
    patch:
      tags:
        - student
      summary: Update some fields of student
      description: Update some fields of student by given student ID.
      parameters:
        - name: studentId
          in: path
          description: ID of the student to update
          required: true
          schema:
            type: integer
      requestBody:
        description: Update existing student
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Student'
        required: true
      responses:
        '200':
          description: Updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Student'
        '400':
          description: Invalid input
        '401':
          description: unauthorized
        '404':
          description: Student not found
        '422':
          description: Validation exception
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ErrorMessage'
      security:
        - student_data_auth: []
    delete:
      tags:
        - student
      summary: Delete student by ID
      description: Delete student by given ID.
      parameters:
        - name: studentId
          in: path
          description: ID of the student to delete
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: Deleted successfully
        '401':
          description: unauthorized
        '404':
          description: Student not found
      security:
        - student_data_auth: []
components:
  schemas:
    HelloWorld:
      type: string
      example: "Hello World!"
    JwtToken:
      type: string
      example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
    Student:
      type: object
      properties:
        id:
          type: integer
          readOnly: true
          example: 1
        gender:
          type: string
          maxLength: 10
          example: female
        title:
          type: string
          maxLength: 20
          example: Miss
        first_name:
          type: string
          maxLength: 50
          example: Terri
        last_name:
          type: string
          maxLength: 50
          example: Lucas
        email:
          type: string
          maxLength: 100
          example: [email protected]
        dob:
          type: string
          description: date of birth
          format: date
          example: 1964-11-23
        registered:
          type: string
          description: date of registration
          format: date-time
          example: 2014-07-23T03:21:42.259Z
        phone:
          type: string
          maxLength: 20
          example: 03-2662-3559
        id_name:
          type: string
          maxLength: 20
          description: national identification number type
          example: TFN
        id_value:
          type: string
          maxLength: 50
          description: national identification number value
          example: '230000682'
        nat:
          type: string
          maxLength: 10
          description: nationality short code
          example: AU
        location:
          $ref: '#/components/schemas/Location'
        picture:
          $ref: '#/components/schemas/Picture'
    Location:
      type: object
      properties:
        street_number:
          type: integer
          example: 2595
        street_name:
          type: string
          maxLength: 100
          example: Main Street
        city:
          type: string
          maxLength: 100
          example: Tamworth
        state:
          type: string
          maxLength: 100
          example: Queensland
        country:
          type: string
          maxLength: 100
          example: Australia
        postcode:
          type: string
          maxLength: 20
          example: '6066'
        timezone:
          type: string
          maxLength: 10
          example: +5:30
    Picture:
      type: object
      properties:
        large:
          type: string
          maxLength: 255
          example: https://randomuser.me/api/portraits/men/75.jpg
        medium:
          type: string
          maxLength: 255
          example: https://randomuser.me/api/portraits/med/men/75.jpg
        thumbnail:
          type: string
          maxLength: 255
          example: https://randomuser.me/api/portraits/thumb/men/75.jpg
    ErrorMessage:
      type: object
      properties:
        field:
          type: string
          example: first_name
        message:
          type: string
          example: Input must be string
  securitySchemes:
    jwt_token_auth:
      type: http
      scheme: basic
    student_data_auth:
      type: http
      scheme: bearer
      bearerFormat: JWT

I’ll just add that my ASP.NET Core code was generated by OpenAPI generator in IntelliJ. After that I hadn’t any authorization, and after added OpenApiSecurityRequirement I got above situation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật