So you need to move your code to your own plugin. I trust you have the skills to do that if you are able to modify the code directly? Install like everyone else. Otherwise your situation is unsupported unless someone has a lot of free time on their hands to work out your novel case.
Please use the plugin architecture if the core logic does not fit your needs. Then at least the basic install is identical. You will thank yourself down the line when updates are just a button click. You will also help anyone who takes over from you and get more timely support here.
The guide you may need is here Beginner's Guide to Creating Discourse Plugins - Part 1
Before going that far, though, you might want to explain why the native SSO support does not suit your needs and perhaps an SME on that functionality can weigh in?