1

So I am following the official documentation for Google sign in with DjangoRestFramework using DJ Rest Auth (this link)

I intend to authenticate with Postman Oauth2 (by following the guide and generating an Access Token) postman oauth page Postman is generating an access token successfully, but I cannot seem to use this authentication in my API calls. Please who knows which step I am missing - I want to handle everything in Postman.

urls.py

urlpatterns = [
path('', Home.as_view(), name='home'),
path('admin/', admin.site.urls),
path('accounts/', include(api_urls, namespace='api')),
path('accounts/login/', GoogleLogin.as_view(), name='google_login'),
path('accounts/', include('rest_framework.urls')),
]

views.py

class GoogleLogin(SocialLoginView):
adapter_class = GoogleOAuth2Adapter
callback_url = 'http://localhost:8080/accounts/google/login/callback/'
client_class = OAuth2Client

On calling an API endpoint, I get an invalid token error: invalid token

If I however visit the Google Login view in my RestFramework UI (in my case http://localhost:8080/accounts/login), I get an endpoint to make a POST, and on making a POST request, a key is generated. Only this key (if used as a Bearer token) works in my API calls. Google View Key generated

How can I authenticate on Google, and make my API calls independent of the DRF UI? Callback URL has been configured on my Google Developer Client.

PS: I feel the answer is in step 6 of the documentation, but I am unable to figure out how to do this in Postman

POST code or token to specified URL(/dj-rest-auth/google/)

kcEmenike
  • 172
  • 1
  • 7

1 Answers1

0

What I did here is from postman go to headers then put Authorization = Token youraccesskey

which in your case Authorization = Token ef057...... Hope it helps