Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CORS support to metadata endpoint. #790

Merged
merged 1 commit into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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