如何从iframe中加载回叫Sso

时间:2019-05-17 18:20:34

标签: javascript html .net

我有一个需要验证用户身份的Sso网址,我想以iframe方式加载此网址,但是在进行SSo身份验证后,sso会在我的应用程序中触发一个回调网址,现在该网址已加载在iframe模式中,我希望此回调将页面显示出iframe模式,然后关闭iframe模式。

我尝试使用负载,因为不使用iframe,但出现cors原点错误

import { Injectable } from '@angular/core';
// import { HubConnectorComponent, HubConnectorRequestOptions } from 'angl-spawebbgrl';
import { parseMessage } from '../shared/parse';
import { ChatContentService } from './chat-content.service';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { TestLibraryService } from './test-library.service';
import { HubMessage } from '../shared/utils';
@Injectable()
export class ChatMessageService {

    public URL = `${this.api.config.URL_BASE}/${this.api.config.URL_SEND_MESSAGE}?${this.api.config.QP_APP_KEY}=${this.api.config.APP_KEY}`;
    public chatBotId = '';
    public userId = '';
    public senderId = '';

    /** Sends a message to hub and returns an observable with the response
     *  @Input HubMessage
     *  @Output HubResponse
     */
    sendMessage(message: string) {

        const body: HubMessage = {
            recipient: {
                id: 'https://consultoriabenevides.com'
            },
            sender: {
                id: this.senderId
            },
            message: {
                text: message
            },
            timestamp: new Date().getTime().toString()
        };

        this.chatService.messages$.next(this.chatService.messages$.getValue().concat(body));

        this.sendMessageHub(body).subscribe(res => {
            this.chatService.messages$.next(this.chatService.messages$.getValue().concat(parseMessage(res)));
        });

    }

    sendMessageHub(body): Observable<any> {

        this.http.post(this.URL, body, { headers: { 'channelBotIdentifier': this.chatBotId } });

    }

    setBotId(chatBotId: string) {
        this.chatBotId = chatBotId;
    }

    setSenderId(senderId: string) {
      this.senderId = senderId;
    }

    constructor(
        private http: HttpClient,
        private chatService: ChatContentService,
        private api: TestLibraryService

    ) { }

}

1 个答案:

答案 0 :(得分:0)

在收到Sso的回调后,我使用了这种方法来分解iframe:

if (window.location !== window.top.location) {
            window.top.location = window.location;
        }