# The redirect\_uri must use https for security reasons.

**URL:** <https://community.hubspot.com/t/the-redirect-uri-must-use-https-for-security-reasons/100310>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [February 16, 2024, 5:15am UTC](https://community.hubspot.com/t/the-redirect-uri-must-use-https-for-security-reasons/100310 "2024-02-16T05:15:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hariomsimform](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hariomsimform/32/201636_2.png) [@Hariomsimform](https://community.hubspot.com/u/Hariomsimform)\
**Post date:** [February 16, 2024, 5:15am UTC](https://community.hubspot.com/t/the-redirect-uri-must-use-https-for-security-reasons/100310/1 "2024-02-16T05:15:33Z")

</div>

I am trying to get token but having this issue:

 ![Screenshot 2024-02-16 104416.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/a/5a74faef6622facd601fb897be14a24ab9232f83.png)

##### Couldn’t complete the connection

The redirect\_uri must use https for security reasons.

Below is my Django Views.py code.  
# views.py

from django.http import HttpResponseRedirect, HttpResponse

import requests

from decouple import config

def oauth\_login(request):

# Construct redirect URI

redirect\_uri = ‘[http://127.0.0.1:8000/oauth/callback](http://127.0.0.1:8000/oauth/callback)’

client\_id = config(“HUBSPOT\_CLIENT\_ID”)

authorization\_url = f’[https://app.hubspot.com/oauth/authorize?client\_id=](https://app.hubspot.com/oauth/authorize?client_id=){client\_id}&redirect\_uri={redirect\_uri}&scope=contacts’

return HttpResponseRedirect(authorization\_url)

def oauth\_callback(request):

# Load environment variables

# Extract authorization code from callback

authorization\_code = request.GET.get(‘code’)

# Exchange authorization code for access token

client\_id = config(‘HUBSPOT\_CLIENT\_ID’)

client\_secret = config(‘HUBSPOT\_CLIENT\_SECRET’)

redirect\_uri = ‘[http://127.0.0.1:8000/oauth/callback](http://127.0.0.1:8000/oauth/callback)’

token\_url = ‘[https://api.hubapi.com/oauth/v1/token](https://api.hubapi.com/oauth/v1/token)’

payload = {

‘grant\_type’: ‘authorization\_code’,

‘client\_id’: client\_id,

‘client\_secret’: client\_secret,

‘redirect\_uri’: redirect\_uri,

‘code’: authorization\_code

}

response = requests.post(token\_url, data=payload)

access\_token = response.json()[‘access\_token’]

# Make API request using access token (Example: Get contacts)

api\_url = ‘[https://api.hubapi.com/crm/v3/objects/contacts](https://api.hubapi.com/crm/v3/objects/contacts)’

headers = {

‘Authorization’: f’Bearer {access\_token}',

‘Content-Type’: ‘application/json’

}

response = requests.get(api\_url, headers=headers)

contacts = response.json()

return HttpResponse(contacts)

---

<div class="post-metadata">

**Author:** ![zach\_threadint](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/zach_threadint/32/46318_2.png) [@zach\_threadint](https://community.hubspot.com/u/zach_threadint)\
**Post date:** [February 16, 2024, 5:33am UTC](https://community.hubspot.com/t/the-redirect-uri-must-use-https-for-security-reasons/100310/2 "2024-02-16T05:33:41Z")

</div>

Hi @Hariomsimform 👋

Your redirect\_uri will need to reference “localhost”, rather than “127.0.0.1”. Assuming you have “[http://localhost:8000/oauth/callback](http://localhost:8000/oauth/callback)” registered as a Redirect URL within your app’s configuration, try

(for both references in your code example)

:

`redirect_uri = 'http://localhost:8000/oauth/callback'`

I hope this proves useful. Please let me know if you have any follow-up questions.
