Check session variable before delivering cached page

>because there must be different caches for different customer groups

Right.

 

>- by default user is in customer group called “guest” and therefore can only see the login page
>- after logging in user is in “user” group and can browse page normaly.

It’s similar I propose you to do:

>1. In case you need to do sign in with 3rd service only once - you should create additional group, when user sign up - he can only see sign in to 3rd service page, as soon as this customer sign in - you change group to EK. Then use only shopware auth.

But I’m still don’t sure, customer account on 3rd service can be edited?

 

>Where is this customer group information stored?

I’m not sure what exactly do you mean:

You can create new group via backend - Configuration -> Basic Settings -> Shop Settings -> Customer groups

Data  stored in s_core_customergroups.

Users tables contain data about group in s_user.customergroup(there is key, not id).

Current customer groupkey you can find in

 Shopware()-\>Session()-\> **sUserGroup**

>How does shopware know which group a user belongs to when opening a page?

You can switch default(guest and customers) group there:

http://joxi.ru/4Akon7gtyWMlkA

 

>What do I need to implement in the custom login function to assign an user to a group?

I can’t provide stable solution for such case, you can edit session, but I don’t know how offten shopware will update session variable. You can edit customer group after sucessfull login, but then you should find a right way to revert usergroup back to guest…