I would like to initiate OAuth
web flow from a button on LWC in Lightning Experience, after redirect on VF page and from VF page back to the original Lightning Page from which the user started.
The problem is that Visualforce and Lightning use different structures for redirection. Visualforce use PageReference
apex class while lightning use Navigation mixin.
I tried to redirect from one Visualforce page to another page where I put LWC in Lightning Out to call the redirection back to the original Lightning Page, but this doesn't work.
Listing of Visualforce Page to contain LWC to redirect back
<apex:page>
<c:LexOut component="c:red" dependencyApp="c:dep"/>
</apex:page>
LexOut Visualforce Component for Lightning Out
<apex:component >
<apex:attribute name="component" type="String" description="Component name" required="true"/>
<apex:attribute name="dependencyApp" type="String" description="Dependency app name" required="true"/>
<apex:includeLightning />
<div id="host"/>
<script>
var myUserContext = "{!$User.UITheme}";
$Lightning.use("{!dependencyApp}", function() {
$Lightning.createComponent(
"{!component}",
{ userContext: myUserContext },
"host",
function(cmp) {
});
});
</script>
</apex:component>
Aura Lightning Out Dependency App
<aura:application access="GLOBAL" extends="ltng:outApp">
<aura:dependency resource="c:red"/>
</aura:application>
LWC Red component
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class Red extends NavigationMixin(LightningElement) {
connectedCallback() {
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: 'Account',
actionName: 'home',
},
});
}
}
Apparently this doesn't work and I tried for now just hardcode the Navigation Mixin current page reference.