forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 18
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
JWT Reworking for Kibana API requests #63
Merged
KjellKod
merged 7 commits into
logrhythm:4.1.10_NM
from
craig-cogdill:getAndStoreJWTFromUrl
Sep 6, 2016
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d51546f
Reading the URL from the kibana startup
f1eb9c3
Regex to capture the token from the iframe URL
36ee02b
Added a Restangular interceptor for adding the JWT to all requests.
4d2a4b8
Pass the JWT as a query parameter of the iframe URL for the GET request
dafe70a
Remove console logs in restangular token cacheing
be3fd7c
Changed name of token to jwt for consistency
7565340
Removed unneeded window.location strings
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 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 |
---|---|---|
|
@@ -11,7 +11,7 @@ define(function (require) { | |
require('elasticsearch'); | ||
require('angular-route'); | ||
require('angular-bindonce'); | ||
|
||
require('restangular'); | ||
|
||
var configFile = JSON.parse(require('text!config')); | ||
|
@@ -49,16 +49,34 @@ define(function (require) { | |
'Pragma': 'no-cache', | ||
'Expires': 0 | ||
}); | ||
var fullUrl = window.location; | ||
var searchUrl = window.location.search; | ||
var hrefUrl = window.location.href; | ||
|
||
// Look for 'token=', then capture all characters | ||
// after (non-greedy) until either end of substring | ||
// or the next ampersand. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great regexp comment! |
||
var jwtPattern = /jwt=(.*?)(&|$)/i; | ||
var jwt = String(hrefUrl).match(jwtPattern); | ||
localStorage.setItem('token', jwt[1]); | ||
RestangularProvider.addResponseInterceptor(function(data, operation, what, url, response, deferred) { | ||
// TODO: standardized error handling - right now we soft fail errors to empty data | ||
|
||
// Redirect API login failure response to login page | ||
if (data.status !== 'success' && data.message && data.message.match(/you must be logged in/gi)) { | ||
location.href = '/login.php'; | ||
} | ||
|
||
return data && data.status === 'success' ? data.data : {error: true, message: data.message}; | ||
}); | ||
RestangularProvider.addFullRequestInterceptor(function() { | ||
const config = { headers: {} }; | ||
const token = localStorage.getItem('token'); | ||
if (token) { | ||
config.headers['Authorization'] = token; | ||
} | ||
return config; | ||
}); | ||
}) | ||
.config(['ngClipProvider', function (ngClipProvider) { | ||
ngClipProvider.setPath('bower_components/zeroclipboard/dist/ZeroClipboard.swf'); | ||
|
This file contains 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
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.
remove this and above line