Skip to content

Commit

Permalink
Add Access-Control-Allow-Origin header to metadata endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
luhn authored and auvipy committed Dec 13, 2021
1 parent 55ce48b commit 6db6901
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion oauthlib/oauth2/rfc6749/endpoints/metadata.py
Expand Up @@ -54,7 +54,8 @@ def create_metadata_response(self, uri, http_method='GET', body=None,
"""Create metadata response
"""
headers = {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
return headers, json.dumps(self.claims), 200

Expand Down
15 changes: 15 additions & 0 deletions tests/oauth2/rfc6749/endpoints/test_metadata.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from oauthlib.oauth2 import MetadataEndpoint, Server, TokenEndpoint

import json
from tests.unittest import TestCase


Expand Down Expand Up @@ -37,6 +38,20 @@ def test_openid_oauth2_preconfigured(self):
self.maxDiff = None
self.assertEqual(openid_claims, oauth2_claims)

def test_create_metadata_response(self):
endpoint = TokenEndpoint(None, None, grant_types={"password": None})
metadata = MetadataEndpoint([endpoint], {
"issuer": 'https://foo.bar',
"token_endpoint": "https://foo.bar/token"
})
headers, body, status = metadata.create_metadata_response('/', 'GET')
assert headers == {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
}
claims = json.loads(body)
assert claims['issuer'] == 'https://foo.bar'

def test_token_endpoint(self):
endpoint = TokenEndpoint(None, None, grant_types={"password": None})
metadata = MetadataEndpoint([endpoint], {
Expand Down

0 comments on commit 6db6901

Please sign in to comment.