drf-social-oauth2 icon indicating copy to clipboard operation
drf-social-oauth2 copied to clipboard

Hi, everyone. Can't get JWT Token

Open GrechkinDV opened this issue 3 years ago • 11 comments

ACTIVATE_JWT is set to True. Though, I still get only Bearer token after convert-token request.

GrechkinDV avatar Jun 12 '21 20:06 GrechkinDV

ACTIVATE_JWT is set to True. Though, I still get only Bearer token after convert-token request. Same here. I've been pulling my hair out due to this

vipinmohan22 avatar Jul 26 '21 06:07 vipinmohan22

Social Oauth

ACTIVATE_JWT = True DRFSO2_URL_NAMESPACE = "drf"

Have you got things like this?

GrechkinDV avatar Jul 26 '21 06:07 GrechkinDV

yes

vipinmohan22 avatar Jul 26 '21 06:07 vipinmohan22

What's about your urls setup?

GrechkinDV avatar Jul 26 '21 07:07 GrechkinDV

path('auth/', include('drf_social_oauth2.urls', namespace='drf')),

did you manage to get it to work?

vipinmohan22 avatar Jul 26 '21 07:07 vipinmohan22

Sorry about the delay. Did you manage to get this fixed? Can you paste more information about your problem?

wagnerdelima avatar Dec 23 '21 09:12 wagnerdelima

I do get a JWT, but I have no idea how to use it in my client.

When I try this:

Authorization: Bearer eyJhbGci...

I get this:

{
    "detail": "Given token not valid for any token type",
    "code": "token_not_valid",
    "messages": [
        {
            "token_class": "AccessToken",
            "token_type": "access",
            "message": "Token has no 'exp' claim"
        }
    ]
}

When I do this:

Authorization: Bearer facebook eyJhbGci...

I get this:

{
    "detail": "Authorization header must contain two space-delimited values",
    "code": "bad_authorization_header"
}

denizdogan avatar Jan 05 '22 16:01 denizdogan

Turned out that I had traces of rest_framework_simplejwt all over my code base. Removing these helped solve my issue.

denizdogan avatar Jan 05 '22 16:01 denizdogan

@GrechkinDV this is definitely not an error by drf-social-oauth2. That might be simplejwt as @denizdogan mentioned.

wagnerdelima avatar Jan 05 '22 16:01 wagnerdelima

So does that mean there's no way to use both rest_framework_simplejwt and drf_social_oauth2

codewitgabi avatar Feb 06 '24 10:02 codewitgabi

So I was able to fix my issue and use both rest_framework_simplejwt and drf_social_oauth2.

  • Firstly in the documentation, it is stated that to authenticate an endpoint you should use Authorization: Bearer <backend> <token> Which doesn't work. I think this should be corrected to Authorization: Bearer <token> as this is what works.
  • To use both packages, I did
SIMPLE_JWT = {
   # other settings
    "AUTH_HEADER_TYPES": ("JWT",),
}

So for rest_framework_simplejwt I use Authorization: JWT <token> and for drf_social_oauth2, I use Authorization: Bearer <token>.

codewitgabi avatar Feb 06 '24 11:02 codewitgabi