In which file should I write my custom authentication?

Do I need to write the authorization customization described in this document in file, file or in another file?

If you’re talking about a custom authentication backend, you can put it in (almost) any file you like - wherever it makes the most sense to you. It can be in its own file or with some other code.

You telling Django where to find it by specifying its location in the AUTHENTICATION_BACKENDS setting.