<template>	
	<view>
		<p style="margin-top: 5px;margin-left: 10px">APPID：</p>
	    <input v-model="formData.clientId" style="background-color: #E4E1E1;margin-top: 10px;margin-left: 10px;margin-right: 5px;height: 35px;" />
	</view>
	<view style="margin-top: 10px;">
		<p style="margin-top: 5px;margin-left: 10px">Redirect Url：</p>
	    <input v-model="formData.redirectUrl" style="background-color: #E4E1E1;margin-left: 10px;margin-right: 10px;margin-top: 5px;height: 35px;" />
	</view>
	
	<view style="margin-top: 10px;">
		<p style="margin-top: 5px;margin-left: 10px">Discovery Url：</p>
	    <input v-model="formData.discoveryUri" style="background-color: #E4E1E1;margin-top: 10px;margin-left: 10px;margin-right: 5px;height: 35px;" />
	</view>
	
	<view style="margin-top: 10px;">
			<p style="margin-top: 5px;margin-left: 10px">endsession_endpoint_uri：</p>
		    <input v-model="formData.endSessionEndpoint" style="background-color: #E4E1E1;margin-left: 10px;margin-right: 10px;height: 35px;" />
		</view>
	
	<div style="margin-top: 40px;">
		<button type="primary"  @click="getAuthenticationIntent">认证</button>
	</div>
	
	<div style="margin-top: 5px;">
		<button type="primary" @click="endSession">清空登录态</button>
	</div>
	
	<p style="margin-top: 20px;">{{Output}}</p>
	<div  style="margin-top: 10px;">
		<p class="multilineText">{{multilineText}}</p>
	</div>



</template>

<script>
	// 获取 module 
	import {innerGetAuthorizationIntent ,AppAuthOptions,innerEndSession} from "@/uni_modules/RJ-AppAuthnCenter";
	
	export default {
		onLoad() {
			
		},
		data() {
		    return {
			APPID:'',
			Output:'',
			multilineText:'',
			formData:{
				clientId:'OC4wNS4wNS4wNy4wMC4wMy4wMS4wMS4w',
				redirectUrl:'https://s10sso.ruishan.cc/gate/public/sdkAuth/index.html',
				endSessionRedirectUrl:'https://s10sso.ruishan.cc/gate/public/sdkAuth/index.html',
				authorizationScope:'openid',
				authorizationEndpointUrl:'https://s10sso.ruishan.cc/cas/oidc/authorize',
				authorizationTokenEndpointUrl:'https://s10sso.ruishan.cc/cas/oidc/accessToken',
				userInfoEndpointUri:'https://s10sso.ruishan.cc/cas/oidc/profile',
				endSessionEndpoint:'https://s10sso.ruishan.cc/cas/logout',
				launchSheme:'net.rj.appauth',
				defaultbrowser:'{"packagename":"","useCustomTab":false }',
				discoveryUri:'https://s10sso.ruishan.cc/cas/oidc/.well-known',
				authorizationScene:0 //0系统浏览器 ,1是webview
			}
		    };
		  },
		methods: {
			
			getAuthenticationIntent() {
				let options = {
					paramA: false,
					fail:  (errCode , errMsg ) => {
						console.log("getAuthenticationIntent error:" + errMsg + errCode)
						this.Output =  "Error:";
						this.multilineText = "errCode:" + errCode + "   errMsg:" + errMsg;			
					},
					success: (res) => {
						console.log("getAuthenticationIntent success:" +res)					
						this.Output =  "Success:";
						this.multilineText = res;
					}
				}
				// 调用异步方法示例		
				console.log('getAuthenticationIntent !!!!...data=' + JSON.stringify(this.formData));
				innerGetAuthorizationIntent(this.formData.clientId,
					this.formData.redirectUrl,
					this.formData.discoveryUri,
					this.formData.launchSheme,
					'com.example.webauth',
					options)
			},
			endSession() {
				// 调用异步方法示例
				console.log('endSession !!!!...data=' + JSON.stringify(this.formData));
				
				
				let options = {
					paramA: false,
					fail:  (errCode , errMsg ) => {
						console.log("endSession error:" + errMsg + errCode)
						this.Output =  "Error:";
						this.multilineText = "errCode:" + errCode + "   errMsg:" + errMsg;			
					},
					success: (res) => {
						console.log("endSession success:" +res)					
						this.Output =  "Success:";
						this.multilineText = res;
					}
				  }

				innerEndSession(this.formData.endSessionEndpoint,
					this.formData.redirectUrl,
					this.formData.launchSheme,
					'com.example.webauth',
					options
					);
					
				this.Output =  '';
				this.multilineText = '';
			}
		}
	}
</script>

<style >
	.picker {
	  padding: 10px;
	  background-color: #FFFFFF;
	  text-align: center;
	}
	
	.multilineText {
	  height: 30px;
	}
	
</style>
