How can generate _forum_session and _t for an user through code/api call or without login to browser?

Can you back up and describe what problem having those cookies is going to solve?

What are you trying to accomplish? Are you trying to have Discourse authenticate against your app? Maybe look at DiscourseConnect - Official Single-Sign-On for Discourse (sso)?