pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.2k stars 2.99k forks source link

Battle.net China implementation #1521

Open jleclanche opened 7 years ago

jleclanche commented 7 years ago

Hey @pennersr, I need your thoughts on this.

Here's how the Battle.net API works:

My plan right now is to publish a test instance of my site using the China-specific endpoints and observe what happens and how the API behaves. I want to do it as close to the way we'll end up implementing it upstream. This is where I need some help.

My current thinking: I have created a custom, china-specific provider and adapter, which subclass their respective BattleNet classes.

Now, despite using a (suspected) different account database, the OAuth database is synced across China and ROTW. That means the SocialApp API keys are the same across all regions. This means we can't straight up create a separate provider... right?

So considering all this... how would I do the following and actually be able to use it for the battlenet app?

from allauth.socialaccount.providers.battlenet.provider import BattleNetProvider
from allauth.socialaccount.providers.battlenet.views import BattleNetAdapter

class BattleNetChinaProvider(BattleNetProvider):
    id = "battlenet_cn"
    name = "Battle.net (China)"

    def extract_uid(self, data):
        return str(data["id"]) + "-cn"

class BattleNetChinaOAuth2Adapter(BattleNetAdapter):
    battlenet_region = "cn"
    battlenet_base_url = "https://www.battlenet.com.cn"
    battlenet_api_url = battlenet_base_url + "/api"

    def get_provider(self):
        return BattleNetChinaProvider(request=self.request)
jleclanche commented 7 years ago

I guess that, if we make an explicitly separate battlenet_cn socialaccount provider, then all I would need is a way to override whatever mechanism gets the matching socialapp from battlenet instead of requiring creation of a separate battlenet_cn socialapp. But how?

derek-adair commented 11 months ago

OH! i totally forgot. You need a discord server for questions / comments / discussions like this.

It's your call but I found on my projects it cut down on a LOT of issue submissions in my github of people looking for general support that end up here. If you dont mind general support requests you should create a "discussion" or "support" tag.

pennersr commented 11 months ago

@derek-adair See: https://github.com/pennersr/django-allauth/discussions

derek-adair commented 11 months ago

Oh! this is fantastic i wasn't aware of this.