Last active
December 28, 2020 21:11
-
-
Save surajp/4f345d2ee5274d5fd6d6536b909050a4 to your computer and use it in GitHub Desktop.
Google OAuth using LWC + VF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement } from 'lwc'; | |
const BASE_URL='https://accounts.google.com/o/oauth2/v2/auth'; | |
export default class Goauth extends LightningElement { | |
doAuth(){ | |
let client_id='<your client id>'; | |
console.log('test'); | |
let redirect_uri=`${window.location.origin}/apex/oauthbroker`; | |
let scope='https%3A//www.googleapis.com/auth/drive.metadata.readonly'; | |
let url=`${BASE_URL}?scope=${scope}&client_id=${client_id}&redirect_uri=${redirect_uri}&response_type=token`; | |
window.open(url); | |
window.onmessage = msg=>{ | |
console.log('>> message '+msg.data); //msg.data contains the access token | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page> | |
<script> | |
if(window.location.hash){ | |
window.opener.postMessage(window.location.hash.substring(1),'<your-lightning-domain>'); | |
} | |
</script> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment