SingleSignOn Interceptor

This commit is contained in:
MaxKey
2022-05-26 15:13:43 +08:00
parent 3a65a66620
commit 3377d957ed
14 changed files with 245 additions and 43 deletions

View File

@@ -1,3 +1,20 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* 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.
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AccoutsComponent } from './accouts.component';

View File

@@ -1,3 +1,20 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* 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.
*/
import { Component, ChangeDetectorRef, OnInit, Input } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';

View File

@@ -44,8 +44,9 @@ export class AuthnService {
) { }
setRedirectUri(redirect_uri: string) {
this.redirect_uri = CryptoJS.enc.Base64url.parse(redirect_uri).toString();
localStorage.setItem('redirect_uri', this.redirect_uri);
this.redirect_uri = CryptoJS.enc.Base64url.parse(redirect_uri).toString(CryptoJS.enc.Utf8);
console.log(`redirect_uri ${this.redirect_uri}`);
localStorage.setItem(CONSTS.REDIRECT_URI, this.redirect_uri);
}
get(authParam: any) {
@@ -91,8 +92,8 @@ export class AuthnService {
subHostName = `${hostnames[hostnames.length - 2]}.${hostnames[hostnames.length - 1]}`;
}
this.cookieService.set(CONSTS.CONGRESS, authJwt.token);
this.cookieService.set(CONSTS.ONLINE_TICKET, authJwt.ticket, { domain: subHostName });
this.cookieService.set(CONSTS.CONGRESS, authJwt.token, { path: '/' });
this.cookieService.set(CONSTS.ONLINE_TICKET, authJwt.ticket, { domain: subHostName, path: '/' });
if (authJwt.remeberMe) {
localStorage.setItem(CONSTS.REMEMBER, authJwt.remeberMe);
@@ -152,10 +153,17 @@ export class AuthnService {
if (url.includes('/passport')) {
url = '/';
}
if (this.redirect_uri != '') {
url = this.redirect_uri;
this.redirect_uri = '';
if (localStorage.getItem(CONSTS.REDIRECT_URI) != null) {
this.redirect_uri = `${localStorage.getItem(CONSTS.REDIRECT_URI)}`;
localStorage.removeItem(CONSTS.REDIRECT_URI);
}
if (this.redirect_uri != '') {
console.log(`redirect_uri ${this.redirect_uri}`);
location.href = this.redirect_uri;
}
this.router.navigateByUrl(url);
});
}

View File

@@ -1,3 +1,20 @@
/*
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
*
* 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.
*/
export function knowHost() {
let hostArray: string[] = new Array('localhost', 'sso.maxkey.top', 'mgt.maxkey.top', 'sso.maxsso.net', 'mgt.maxsso.net');
for (var i = 0; i < hostArray.length; i++) {