func (keycloak *KeycloakOAuthProvider) LinkCallback(ctx *app.LinkcallbackLoginContext, brokerEndpoint string, clientID string) error {
	state := ctx.State
	errorMessage := ctx.Params.Get("error")
	if state == nil {
		jsonapi.JSONErrorResponse(ctx, goa.ErrInternal("State is empty. "+errorMessage))
	}
	if errorMessage != "" {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrInternal(errorMessage))
	}

	next := ctx.Next
	if next != nil {
		// Link the next provider
		sessionState := ctx.SessionState
		clientSession := ctx.ClientSession
		if sessionState == nil || clientSession == nil {
			log.Error(ctx, map[string]interface{}{
				"state": state,
			}, "Session state or client session state is empty")
			jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest("Session state or client session state is empty"))
			return ctx.Unauthorized(jerrors)
		}
		providerURL, err := getProviderURL(ctx.RequestData, *state, *sessionState, *clientSession, *next, nextProvider(*next), brokerEndpoint, clientID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrInternal(err.Error()))
		}
		ctx.ResponseData.Header().Set("Location", providerURL)
		return ctx.TemporaryRedirect()
	}

	// No more providers to link. Redirect back to the original referrer
	originalReferrer, err := keycloak.getReferrer(ctx, *state)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"state": state,
			"err":   err,
		}, "uknown state")
		jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrUnauthorized("uknown state. " + err.Error()))
		return ctx.Unauthorized(jerrors)
	}

	ctx.ResponseData.Header().Set("Location", originalReferrer)
	return ctx.TemporaryRedirect()
}
// LinkCallback redirects to original referrer when Identity Provider account are linked to the user account
LinkCallback redirects to original referrer when Identity Provider account are linked to the user account
// LinkCallback redirects to original referrer when Identity Provider account are linked to the user account
func (keycloak *KeycloakOAuthProvider) LinkCallback(ctx *app.LinkcallbackLoginContext, brokerEndpoint string, clientID string) error {
	state := ctx.State
	errorMessage := ctx.Params.Get("error")
	if state == nil {
		jsonapi.JSONErrorResponse(ctx, goa.ErrInternal("State is empty. "+errorMessage))
	}
	if errorMessage != "" {
		return jsonapi.JSONErrorResponse(ctx, goa.ErrInternal(errorMessage))
	}
	next := ctx.Next
	if next != nil {
		sessionState := ctx.SessionState
		clientSession := ctx.ClientSession
		if sessionState == nil || clientSession == nil {
			log.Error(ctx, map[string]interface{}{
				"state": state,
			}, "Session state or client session state is empty")
			jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrBadRequest("Session state or client session state is empty"))
			return ctx.Unauthorized(jerrors)
		}
		providerURL, err := getProviderURL(ctx.RequestData, *state, *sessionState, *clientSession, *next, nextProvider(*next), brokerEndpoint, clientID)
		if err != nil {
			return jsonapi.JSONErrorResponse(ctx, goa.ErrInternal(err.Error()))
		}
		ctx.ResponseData.Header().Set("Location", providerURL)
		return ctx.TemporaryRedirect()
	}
	originalReferrer, err := keycloak.getReferrer(ctx, *state)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"state": state,
			"err":   err,
		}, "uknown state")
		jerrors, _ := jsonapi.ErrorToJSONAPIErrors(goa.ErrUnauthorized("uknown state. " + err.Error()))
		return ctx.Unauthorized(jerrors)
	}
	ctx.ResponseData.Header().Set("Location", originalReferrer)
	return ctx.TemporaryRedirect()
}
func ( keycloak * KeycloakOAuthProvider ) LinkCallback ( ctx * app . LinkcallbackLoginContext , brokerEndpoint string , clientID string ) error { state := ctx . State errorMessage := ctx . Params . Get ( " " ) if state == nil { jsonapi . JSONErrorResponse ( ctx , goa . ErrInternal ( " " + errorMessage ) ) } if errorMessage != " " { return jsonapi . JSONErrorResponse ( ctx , goa . ErrInternal ( errorMessage ) ) } next := ctx . Next if next != nil { sessionState := ctx . SessionState clientSession := ctx . ClientSession if sessionState == nil || clientSession == nil { log . Error ( ctx , map [ string ] interface { } { " " : state , } , " " ) jerrors , _ := jsonapi . ErrorToJSONAPIErrors ( goa . ErrBadRequest ( " " ) ) return ctx . Unauthorized ( jerrors ) } providerURL , err := getProviderURL ( ctx . RequestData , * state , * sessionState , * clientSession , * next , nextProvider ( * next ) , brokerEndpoint , clientID ) if err != nil { return jsonapi . JSONErrorResponse ( ctx , goa . ErrInternal ( err . Error ( ) ) ) } ctx . ResponseData . Header ( ) . Set ( " " , providerURL ) return ctx . TemporaryRedirect ( ) } originalReferrer , err := keycloak . getReferrer ( ctx , * state ) if err != nil { log . Error ( ctx , map [ string ] interface { } { " " : state , " " : err , } , " " ) jerrors , _ := jsonapi . ErrorToJSONAPIErrors ( goa . ErrUnauthorized ( " " + err . Error ( ) ) ) return ctx . Unauthorized ( jerrors ) } ctx . ResponseData . Header ( ) . Set ( " " , originalReferrer ) return ctx . TemporaryRedirect ( ) }
LinkCallback redirects to original referrer when Identity Provider account are linked to the user account
LinkCallback redirects to original referrer when Identity Provider account are linked to the user account
// Link the next provider // No more providers to link. Redirect back to the original referrer