1. Using Outsystems default Login Screen,
a. you can check if userid is null then you can call external api for authenticate user.
b. if success then you will find user in Outsystems User table [ using userid or email depends upon use case, if your are getting unique identification from token to identify use, you can use that ]. if user found in OS DB then you can create session/login using userid without password. if user not exist then you can create user in outsystem DB and then create login/session in outsystems and continue.
c. if you want to logout , you can call external api to log out and destroy session in outsystms. DB.
2. using external SSO login screen, like Office 365 .
you can check if userid is null then you will redirect to SSO login screen using external URL. you have to create a callback screen so that SSO will send Token in to header or body of callback screen back to your app. you will get user's unique id from header or body then you can perform same flow as i described above. you can refer Outsystem IDP integration for more detail.