This repository was archived by the owner on Nov 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 356
Oauth authentication rebase #3763
Merged
ocket8888
merged 43 commits into
apache:master
from
mattjackson220:oauth_authentication_rebase
Aug 5, 2019
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
047c03c
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 9d472df
Updated changelog.md and added test
mattjackson220 b2c5104
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 f5e7b39
Updated changelog.md and added test
mattjackson220 0ad9460
minor format fixes
mattjackson220 9eef75c
Updates per comments on PR
mattjackson220 0a4c33e
Updates per comments on PR
mattjackson220 61a3d80
updates per comments
mattjackson220 e4ca745
added /sso redirect to root app to comply with OAuth standards
mattjackson220 ac2021e
updates per comments
mattjackson220 953f6da
updates per comments
mattjackson220 4afa116
updated to use authorization code instead of token, getting rid of im…
mattjackson220 3682c53
updated so code is in POST body
mattjackson220 282b733
updated so all parameters are in POST body
mattjackson220 024b60d
updated to parse token from json or as response body
mattjackson220 eef7558
updated per comments
mattjackson220 03f0140
update per comment
mattjackson220 4ca5256
update per comments
mattjackson220 1d54ad8
vendored dgrijalva/jwt-go and lestrrat-go/jwx
mattjackson220 6ba0797
update for weasel with new dependencies
mattjackson220 e478fbb
update per comment
mattjackson220 7f987f9
update per comment
mattjackson220 e0bda5f
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 3cb1740
Updated changelog.md and added test
mattjackson220 92842a5
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 e3fcdc0
Updated changelog.md and added test
mattjackson220 71eb89d
Updates per comments on PR
mattjackson220 839c8ea
updated to use authorization code instead of token, getting rid of im…
mattjackson220 502bea7
update per comment
mattjackson220 2701f6c
update per comments
mattjackson220 c5c5bec
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 af29a08
Updated changelog.md and added test
mattjackson220 f434828
Updates per comments on PR
mattjackson220 5ae636e
updated to use authorization code instead of token, getting rid of im…
mattjackson220 4ad3b5e
update per comment
mattjackson220 fc731b4
Setup for Opt-In Integration with OAuth provider including Traffic Po…
mattjackson220 b203876
Updated changelog.md and added test
mattjackson220 3285f0d
Updates per comments on PR
mattjackson220 353ab26
updated to use authorization code instead of token, getting rid of im…
mattjackson220 1846696
update per comment
mattjackson220 d8ccedf
updated per comments
mattjackson220 1da32f5
minor update per comment
mattjackson220 9b6b8cf
minor update per comment
mattjackson220 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
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
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,92 @@ | ||
| .. | ||
| .. | ||
| .. 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. | ||
| .. | ||
| .. _oauth_login: | ||
|
|
||
| ********************* | ||
| Configure OAuth Login | ||
| ********************* | ||
|
|
||
| An opt-in configuration for SSO using OAuth is supported and can be configured through the :file:`/opt/traffic_portal/public/traffic_portal_properties.json` and :file:`/opt/traffic_ops/app/conf/cdn.conf` files. OAuth uses a third party provider to authenticate the user. Once enabled, the Traffic Portal Login page will no longer accept username and password but instead will authenticate using OAuth. This will redirect to the ``oAuthUrl`` from :file:`/opt/traffic_portal/public/traffic_portal_properties.json` which will authenticate the user then redirect to the new ``/sso`` page with an authorization code. The new ``/sso`` page will then construct the full URL to exchange the authorization code for a JSON Web Token, and ``POST`` this information to the :ref:`to-api-user-login-oauth` API endpoint. The :ref:`to-api-user-login-oauth` API endpoint will ``POST`` to the URL provided and receive JSON Web Token. The :ref:`to-api-user-login-oauth` API endpoint will decode the token, validate that it is between the issued time and the expiration time, and validate that the public key set URL is allowed by the list of whitelisted URLs read from :file:`/opt/traffic_ops/app/conf/cdn.conf`. It will then authorize the user from the database and return a mojolicious cookie as per the normal login workflow. | ||
|
|
||
| .. Note:: Ensure that the user names in the Traffic Ops database match the value returned in the `sub` field in the response from the OAuth provider when setting up with the OAuth provider. The `sub` field is used to reference the roles in the Traffic Ops database in order to authorize the user. | ||
|
|
||
| .. Note:: OAuth providers sometimes do not return the public key set URL but instead require a locally stored key. This functionality is not currently supported and will require further development. | ||
|
|
||
| .. Note:: The ``POST`` from the API to the OAuth provider to exchange the code for a token expects the response to have the token in JSON format with `access_token` as the desired field (and can include other fields). It also supports a response with just the token itself as the body. Further development work will need to be done to allow other resposne forms or other response fields. | ||
|
|
||
| .. Note:: Users must exist in both Traffic Ops as well as in the OAuth provider's system. The user's rights are defined by the :term:`role` assigned to the user. | ||
|
|
||
| To configure OAuth login: | ||
|
|
||
| - Set up authentication with a third party OAuth provider. | ||
|
|
||
| - Update :file:`/opt/traffic_portal/public/traffic_portal_properties.json` and ensure the following properties are set up correctly: | ||
|
|
||
| .. table:: OAuth Configuration Property Definitions In traffic_portal_properties.json | ||
|
|
||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| | Name | Type | Description | | ||
| +==============================+============+===========================================================================================================================================+ | ||
| | enabled | boolean | Allow OAuth SSO login | | ||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| | oAuthUrl | string | URL to your OAuth provider | | ||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| | redirectUriParameterOverride | string | Query parameter override if the oAuth provider requires a different key for the redirect_uri parameter, defaults to ``redirect_uri`` | | ||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| | clientId | string | Client id registered with OAuth provider, passed in with `client_id` parameter | | ||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
| | oAuthCodeTokenUrl | string | URL to your OAuth provider's endpoint for exchanging the code (from oAuthUrl) for a token | | ||
| +------------------------------+------------+-------------------------------------------------------------------------------------------------------------------------------------------+ | ||
|
|
||
|
|
||
| .. code-block:: json | ||
| :caption: Example OAuth Configuration Properties In traffic_portal_properties.json | ||
|
|
||
| { | ||
| "oAuth": { | ||
| "_comment": "Opt-in OAuth properties for SSO login. See http://traffic-control-cdn.readthedocs.io/en/release-4.0.0/admin/quick_howto/oauth_login.html for more details. redirectUriParameterOverride defaults to redirect_uri if left blank.", | ||
| "enabled": true, | ||
| "oAuthUrl": "example.oauth.com", | ||
| "redirectUriParameterOverride": "", | ||
| "clientId": "", | ||
| "oAuthCodeTokenUrl": "example.oauth.com/oauth/token" | ||
| } | ||
| } | ||
|
|
||
| - Update :file:`/opt/traffic_ops/app/conf/cdn.conf` property traffic_ops_golang.whitelisted_oauth_urls to contain all allowed domains for the JSON key set (Use ``*`` for wildcard): | ||
|
|
||
| .. table:: OAuth Configuration Property Definitions In cdn.conf | ||
|
|
||
| +--------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------+ | ||
| | Name | Type | Description | | ||
| +==========================+====================+=================================================================================================================+ | ||
| | whitelisted_oauth_urls | Array of strings | List of whitelisted URLs for the JSON public key set returned by OAuth provider. Can contain ``*`` wildcards. | | ||
| +--------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------+ | ||
| | oauth_client_secret | string | Client secret registered with OAuth provider to verify client, passed in with `client_secret` parameter | | ||
| +--------------------------+--------------------+-----------------------------------------------------------------------------------------------------------------+ | ||
|
|
||
|
|
||
| .. code-block:: json | ||
| :caption: Example OAuth Configuration Properties In cdn.conf | ||
|
|
||
| { | ||
| "traffic_ops_golang": { | ||
| "whitelisted_oauth_urls": [ | ||
| "oauth.example.com", | ||
| "*.example.com" | ||
| ], | ||
| "oauth_client_secret": "secret" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| .. | ||
| .. | ||
| .. 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. | ||
| .. | ||
|
|
||
| .. _to-api-user-login-oauth: | ||
|
|
||
| ******************** | ||
| ``user/login/oauth`` | ||
| ******************** | ||
| .. versionadded:: 1.4 | ||
|
|
||
| ``POST`` | ||
| ======== | ||
|
|
||
| Authentication of a user by exchanging a code for an encrypted JSON Web Token from an OAuth service. Traffic Ops will ``POST`` to the authCodeTokenUrl to exchange the code for an encrypted JSON Web Token. It will then decode and validate the token, validate the key set domain, and send back a session cookie. | ||
|
|
||
| :Auth. Required: No | ||
| :Roles Required: None | ||
| :Response Type: ``undefined`` | ||
|
|
||
| Request Structure | ||
| ----------------- | ||
| :authCodeTokenUrl: URL for code-to-token conversion | ||
| :code: Code | ||
| :clientId: Client Id | ||
| :redirectUri: Redirect URI | ||
|
|
||
| .. code-block:: http | ||
| :caption: Request Example | ||
|
|
||
| POST /api/1.4/user/login/oauth HTTP/1.1 | ||
| Host: trafficops.infra.ciab.test | ||
| User-Agent: curl/7.47.0 | ||
| Accept: */* | ||
| Cookie: mojolicious=... | ||
| Content-Length: 26 | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "authCodeTokenUrl": "https://url-to-convert-code-to-token.example.com", | ||
| "code": "AbCd123", | ||
| "clientId": "oauthClientId", | ||
| "redirectUri": "https://traffic-portal.example.com/sso" | ||
| } | ||
|
|
||
| Response Structure | ||
| ------------------ | ||
| .. code-block:: http | ||
| :caption: Response Example | ||
|
|
||
| HTTP/1.1 200 OK | ||
| Access-Control-Allow-Credentials: true | ||
| Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Set-Cookie, Cookie | ||
| Access-Control-Allow-Methods: POST,GET,OPTIONS,PUT,DELETE | ||
| Access-Control-Allow-Origin: * | ||
| Content-Type: application/json | ||
| Set-Cookie: mojolicious=...; Path=/; Expires=Thu, 13 Dec 2018 21:21:33 GMT; HttpOnly | ||
| Whole-Content-Sha512: UdO6T3tMNctnVusDXzRjVwwYOnD7jmnBzPEB9PvOt2bHajTv3SKTPiIZjDzvhU6EX4p+JoG4fA5wlhgxpsejIw== | ||
| X-Server-Name: traffic_ops_golang/ | ||
| Date: Thu, 13 Dec 2018 15:21:33 GMT | ||
| Content-Length: 65 | ||
|
|
||
| { "alerts": [ | ||
| { | ||
| "text": "Successfully logged in.", | ||
| "level": "success" | ||
| } | ||
| ]} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.