-
Notifications
You must be signed in to change notification settings - Fork 340
feat(auth): Adding SAMLProviderConfig type and the getter method #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright 2020 Google Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Firebase auth providers management sub module.""" | ||
|
||
import requests | ||
|
||
from firebase_admin import _auth_utils | ||
|
||
|
||
class ProviderConfig: | ||
"""Parent type for all authentication provider config types.""" | ||
|
||
def __init__(self, data): | ||
self._data = data | ||
|
||
@property | ||
def provider_id(self): | ||
name = self._data['name'] | ||
return name.split('/')[-1] | ||
|
||
@property | ||
def display_name(self): | ||
return self._data.get('displayName') | ||
|
||
@property | ||
def enabled(self): | ||
return self._data['enabled'] | ||
|
||
|
||
class SAMLProviderConfig(ProviderConfig): | ||
"""Represents he SAML auth provider configuration. | ||
|
||
See http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html.""" | ||
|
||
@property | ||
def idp_entity_id(self): | ||
return self._data.get('idpConfig', {})['idpEntityId'] | ||
|
||
@property | ||
def sso_url(self): | ||
return self._data.get('idpConfig', {})['ssoUrl'] | ||
|
||
@property | ||
def x509_certificates(self): | ||
certs = self._data.get('idpConfig', {})['idpCertificates'] | ||
return [c['x509Certificate'] for c in certs] | ||
|
||
@property | ||
def request_signing_enabled(self): | ||
return self._data.get('idpConfig', {})['signRequest'] | ||
|
||
@property | ||
def callback_url(self): | ||
return self._data.get('spConfig', {})['callbackUri'] | ||
|
||
@property | ||
def rp_entity_id(self): | ||
return self._data.get('spConfig', {})['spEntityId'] | ||
|
||
|
||
class ProviderConfigClient: | ||
"""Client for managing Auth provider configurations.""" | ||
|
||
PROVIDER_CONFIG_URL = 'https://identitytoolkit.googleapis.com/v2beta1' | ||
|
||
def __init__(self, http_client, project_id, tenant_id=None): | ||
self.http_client = http_client | ||
self.base_url = '{0}/projects/{1}'.format(self.PROVIDER_CONFIG_URL, project_id) | ||
if tenant_id: | ||
self.base_url += '/tenants/{0}'.format(tenant_id) | ||
|
||
def get_saml_provider_config(self, provider_id): | ||
if not isinstance(provider_id, str): | ||
raise ValueError( | ||
'Invalid SAML provider ID: {0}. Provider ID must be a non-empty string.'.format( | ||
provider_id)) | ||
if not provider_id.startswith('saml.'): | ||
raise ValueError('Invalid SAML provider ID: {0}.'.format(provider_id)) | ||
|
||
body = self._make_request('get', '/inboundSamlConfigs/{0}'.format(provider_id)) | ||
return SAMLProviderConfig(body) | ||
|
||
def _make_request(self, method, path, body=None): | ||
url = '{0}{1}'.format(self.base_url, path) | ||
try: | ||
return self.http_client.body(method, url, json=body) | ||
except requests.exceptions.RequestException as error: | ||
raise _auth_utils.handle_auth_backend_error(error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be used interchangeably?
rp
andsp
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backend APIs use
sp
(service provider) nomenclature. We map that torp
(relying party) in the Admin API surface. This was decision made by the Auth team.