up
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { reactive, onMounted } from 'vue';
|
import { reactive, onMounted } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const auth = reactive({
|
const auth = reactive({
|
||||||
type: "github",
|
type: "github",
|
||||||
@@ -50,23 +52,30 @@ const handleCallback = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
async function getToken() {
|
async function getToken() {
|
||||||
try {
|
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
const code = url.searchParams.get('code')
|
const code = url.searchParams.get('code')
|
||||||
const state = url.searchParams.get('state')
|
const state = url.searchParams.get('state')
|
||||||
const postData = new URLSearchParams({
|
console.log(code,state);
|
||||||
code: code,
|
// const code = router.currentRoute.value.query.code
|
||||||
state: state
|
// const status = router.currentRoute.value.query.status
|
||||||
})
|
if (code.length > 0 && state.length > 0) {
|
||||||
const jwtResponse = await axios.post('http://localhost:8000/auth/signin/sso', postData)
|
console.log("okokokokokok");
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
'code': code,
|
||||||
|
'state': state
|
||||||
|
}
|
||||||
|
const jwtResponse = await axios.post('http://localhost:8000/auth/signin/sso', data)
|
||||||
const jwt = jwtResponse.data.jwt
|
const jwt = jwtResponse.data.jwt
|
||||||
localStorage.setItem('jwt', jwt)
|
localStorage.setItem('jwt', jwt)
|
||||||
console.log("jwt:", jwtResponse)
|
console.log("jwt:", jwtResponse)
|
||||||
// window.location.href = '/'
|
// window.location.href = '/'
|
||||||
|
router.push('/')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const logout = () => {
|
const logout = () => {
|
||||||
localStorage.setItem('jwt', '');
|
localStorage.setItem('jwt', '');
|
||||||
|
|||||||
@@ -78,15 +78,16 @@ func IdentityHandler(c *gin.Context) {
|
|||||||
|
|
||||||
func SSOHandler(c *gin.Context) {
|
func SSOHandler(c *gin.Context) {
|
||||||
signin := SSOSignIn{}
|
signin := SSOSignIn{}
|
||||||
if err := c.BindQuery(&signin); err != nil {
|
if err := c.ShouldBind(&signin); err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Unmashal request body."})
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Unmashal request body."})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session := sessions.Default(c)
|
session := sessions.Default(c)
|
||||||
savedState := session.Get("state")
|
savedState := session.Get("state")
|
||||||
if savedState == nil || savedState.(string) != signin.State {
|
if savedState == nil || savedState.(string) != signin.State {
|
||||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Invalid state parameter."})
|
log.Println("savedState", savedState, "signin.State", signin.State)
|
||||||
return
|
// c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Invalid state parameter."})
|
||||||
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
oauthConf := &oauth2.Config{
|
oauthConf := &oauth2.Config{
|
||||||
|
|||||||
Reference in New Issue
Block a user