Friends Of AdonisFriends Of Adonis

Security

You can define which security mechanisms should be used for your operations using the @ApiSecurity decorator.

app/controllers/users_controller.ts
import {  } from '@foadonis/openapi/decorators'
 
@('basic')
export default class  {}

The mechanisms must be define on your document, you can do this directly from your config/openapi.ts configuration file.

config/openapi.ts
import {  } from '@foadonis/openapi'
 
export default ({
  : {
    : {
      : {
        : {
          : 'http',
          : 'basic',
        },
      },
    },
  },
})

Examples

Basic authentication

app/controllers/users_controller.ts
import {  } from '@foadonis/openapi/decorators'
 
@()
export default class  {}
config/openapi.ts
import {  } from '@foadonis/openapi'
 
export default ({
  : {
    : {
      : {
        : {
          : 'http',
          : 'basic',
        },
      },
    },
  },
})

Bearer authentication

app/controllers/users_controller.ts
import {  } from '@foadonis/openapi/decorators'
 
@()
export default class  {}
config/openapi.ts
import {  } from '@foadonis/openapi'
 
export default ({
  : {
    : {
      : {
        : {
          : 'http',
          : 'bearer',
          : 'JWT',
        },
      },
    },
  },
})

OAuth2 authentication

app/controllers/users_controller.ts
import {  } from '@foadonis/openapi/decorators'
 
@('users:read', 'global:read')
export default class  {}
config/openapi.ts
import {  } from '@foadonis/openapi'
 
export default ({
  : {
    : {
      : {
        : {
          : 'oauth2',
          : {
            : {
              : 'https://example.com/api/oauth/dialog',
              : {
                'users:read': 'read users',
                'global:read': 'global read',
              },
            },
          },
        },
      },
    },
  },
})

On this page