Skip to content

Commit bf5e833

Browse files
stiwarisemanticbitsShivam Tiwarijimmyfagan
authored
BB2-4004: Remove the ability for developers to access PKCE = false for test client (#1378)
* BB2-4004 Remove the ability for developers to access PKCE = false for test client * Forced pkce * Remove comment * Fix --------- Co-authored-by: Shivam Tiwari <shivam.tiwari@icf.com> Co-authored-by: jimmyfagan <90421499+jimmyfagan@users.noreply.github.com>
1 parent cb5df73 commit bf5e833

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

apps/testclient/templates/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ <h2>Step 1: Sample Authorization</h2>
4444

4545
<br />
4646

47-
<a id="auth_link_v2" href="{% url 'authorize_link_v2' %}?pkce=true" class="ds-c-button ds-u-margin-y--2 ds-c-button--solid ds-u-color--white">Get a Sample Authorization Token</a>
47+
<a id="auth_link_v2" href="{% url 'authorize_link_v2' %}" class="ds-c-button ds-u-margin-y--2 ds-c-button--solid ds-u-color--white">Get a Sample Authorization Token</a>
4848
{% endif %}
4949

5050
<!-- If a user DOES have a token, reflect the success of that action -->

apps/testclient/utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..dot_ext.models import Application
1111

1212

13-
def test_setup(include_client_secret=True, v2=False, pkce=False):
13+
def test_setup(include_client_secret=True, v2=False):
1414
response = OrderedDict()
1515
ver = 'v2' if v2 else 'v1'
1616
response['api_ver'] = ver
@@ -29,12 +29,11 @@ def test_setup(include_client_secret=True, v2=False, pkce=False):
2929
response['redirect_uri'] = '{}{}'.format(host, settings.TESTCLIENT_REDIRECT_URI)
3030
response['coverage_uri'] = '{}/{}/fhir/Coverage/'.format(host, ver)
3131

32-
if pkce:
33-
auth_data = __generate_auth_data()
34-
response['code_challenge_method'] = "S256"
35-
response['code_verifier'] = auth_data['code_verifier']
36-
response['code_challenge'] = auth_data['code_challenge']
37-
response['state'] = auth_data['state']
32+
auth_data = __generate_auth_data()
33+
response['code_challenge_method'] = "S256"
34+
response['code_verifier'] = auth_data['code_verifier']
35+
response['code_challenge'] = auth_data['code_challenge']
36+
response['state'] = auth_data['state']
3837

3938
response['authorization_uri'] = '{}/{}/o/authorize/'.format(host, ver)
4039
response['token_uri'] = '{}/{}/o/token/'.format(host, ver)

apps/testclient/views.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from requests_oauthlib import OAuth2Session
1111
from rest_framework import status
1212
from urllib.parse import parse_qs, urlparse
13+
1314
from waffle.decorators import waffle_switch
1415

1516
from .utils import test_setup, get_client_secret, extract_page_nav
@@ -307,22 +308,21 @@ def authorize_link_v2(request):
307308
@never_cache
308309
@waffle_switch('enable_testclient')
309310
def authorize_link(request, v2=False):
310-
pkce_enabled = request.GET.get('pkce')
311-
request.session.update(test_setup(v2=v2, pkce=pkce_enabled))
311+
request.session.update(test_setup(v2=v2))
312312
oas = _get_oauth2_session_with_redirect(request)
313-
authorization_url = None
314-
if pkce_enabled:
315-
authorization_url = oas.authorization_url(
316-
request.session['authorization_uri'],
317-
request.session['state'],
318-
code_challenge=request.session['code_challenge'],
319-
code_challenge_method=request.session['code_challenge_method'])[0]
320-
else:
321-
authorization_url = oas.authorization_url(
322-
request.session['authorization_uri'])[0]
323313

324-
return render(request, 'authorize.html',
325-
{"authorization_url": authorization_url, "api_ver": "v2" if v2 else "v1"})
314+
authorization_url = oas.authorization_url(
315+
request.session['authorization_uri'],
316+
request.session['state'],
317+
code_challenge=request.session['code_challenge'],
318+
code_challenge_method=request.session['code_challenge_method']
319+
)[0]
320+
321+
return render(
322+
request,
323+
'authorize.html',
324+
{"authorization_url": authorization_url, "api_ver": "v2" if v2 else "v1"}
325+
)
326326

327327

328328
def _pagination_info(request, last_url):

0 commit comments

Comments
 (0)