Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating Passwords From Keycloak To Django #61

Open
dev-aakash1998 opened this issue Aug 12, 2021 · 0 comments
Open

Migrating Passwords From Keycloak To Django #61

dev-aakash1998 opened this issue Aug 12, 2021 · 0 comments

Comments

@dev-aakash1998
Copy link

Hi, I saw your code pertaining to credential migration from django to keycloak.
I have a use-case where I want Django Users and Keycloak Users to be synced both ways
So now I am designing an Interface which queries Keycloak DB directly for the credentials and inserts into Django Auth User Model. I referred to your code in services/users.py

def credential_representation_from_hash(hash_, temporary=False):
    algorithm, hashIterations, salt, hashedSaltedValue = hash_.split('$')

    return {
        'type': 'password',
        'hashedSaltedValue': hashedSaltedValue,
        'algorithm': algorithm.replace('_', '-'),
        'hashIterations': int(hashIterations),
        'salt': base64.b64encode(salt.encode()).decode('ascii').strip(),
        'temporary': temporary
    }

I tried to backtrack for syncing user credentials from keycloak to django, my credential looks something like this

{"value":"GnDj7oVoD+/YW00wtQXEwZWCXr+O4FSbUpy8T+CjVK53NDfRXS5NHafDm0Rjgo+ttkerhn1Gtokyt+sEEq7TfA==","salt":"F9v+ZT4T9dQMLtuThTqqZQ==","additionalParameters":{}} 

I have tried using the original salt, I also tried to encode the salt and then insert it, but in both cases I get wrong password from django

In [20]: salt2 = 'F9v+ZT4T9dQMLtuThTqqZQ=='                                                                                                                                                                                                   

In [21]: b64encode(salt2.encode()).decode('ascii').strip()                                                                                                                                                                                    
Out[21]: 'Rjl2K1pUNFQ5ZFFNTHR1VGhUcXFaUT09'

The password field in my Django DB looks something like this

pbkdf2_sha265$27500$Rjl2K1pUNFQ5ZFFNTHR1VGhUcXFaUT09$GnDj7oVoD+/YW00wtQXEwZWCXr+O4FSbUpy8T+CjVK53NDfRXS5NHafDm0Rjgo+ttkerhn1Gtokyt+sEEq7TfA==

What am I doing wrong here? Does Keycloak Use some other logic to encode its salt? If yes, then how should I tackle it?
Any help will be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant