mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
storing token in localStorage
This commit is contained in:
parent
5f950d21c4
commit
0be010bb49
1 changed files with 17 additions and 15 deletions
|
@ -5,6 +5,22 @@ var app = angular.module('app', [
|
||||||
'ui.filters'
|
'ui.filters'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// First, parse the query string
|
||||||
|
var params = {}, queryString = location.hash.substring(1),
|
||||||
|
regex = /([^&=]+)=([^&]*)/g, m;
|
||||||
|
while (m = regex.exec(queryString)) {
|
||||||
|
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if the user is authenticated we should add Basic
|
||||||
|
// auth token to each request.
|
||||||
|
if (params.access_token) {
|
||||||
|
localStorage.setItem("access_token", params.access_token);
|
||||||
|
history.replaceState({}, document.title, location.pathname);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) {
|
app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) {
|
||||||
$routeProvider.when('/', {
|
$routeProvider.when('/', {
|
||||||
|
@ -141,21 +157,7 @@ app.config(['$routeProvider', '$locationProvider', '$httpProvider', function($ro
|
||||||
// use the HTML5 History API
|
// use the HTML5 History API
|
||||||
$locationProvider.html5Mode(true);
|
$locationProvider.html5Mode(true);
|
||||||
|
|
||||||
// First, parse the query string
|
$httpProvider.defaults.headers.common.Authorization = 'Bearer '+localStorage.getItem('access_token');
|
||||||
var params = {}, queryString = location.hash.substring(1),
|
|
||||||
regex = /([^&=]+)=([^&]*)/g, m;
|
|
||||||
while (m = regex.exec(queryString)) {
|
|
||||||
params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// if the user is authenticated we should add Basic
|
|
||||||
// auth token to each request.
|
|
||||||
if (params.access_token) {
|
|
||||||
$httpProvider.defaults.headers.common.Authorization = 'Bearer '+params.access_token;
|
|
||||||
window.history.replaceState( {} , document.title, '/sync' );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$httpProvider.interceptors.push(function($q, $location) {
|
$httpProvider.interceptors.push(function($q, $location) {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue