Created
January 29, 2020 19:09
-
-
Save dhaniksahni/8172934bb067525587b715119ac02cc7 to your computer and use it in GitHub Desktop.
This file contains 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
<aura:component controller="GoogleAuthService" implements="lightning:isUrlAddressable,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> | |
<aura:attribute name="accessToken" type="String" /> | |
<lightning:card title="Google Transcription"> | |
<lightning:button variant="brand" label="Authorize Google" title="Google Drive Auth" onclick="{! c.doAuth }" /> | |
</lightning:card> | |
</aura:component> |
This file contains 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
({ | |
doInit : function(component, event, helper) { | |
if(component.get("v.pageReference") != undefined && component.get("v.pageReference") != 'undefined') { | |
var code = component.get("v.pageReference").state.code; | |
var url = window.location.href; | |
console.log('url',url); | |
function getParameterByName(name, url) { | |
if (!url) url = window.location.href; | |
name = name.replace(/[\[\]]/g, '\\$&'); | |
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | |
results = regex.exec(url); | |
console.log('===results==',results); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
} | |
var code = getParameterByName('code'); | |
if(code != undefined) { | |
var action = component.get('c.getAccessToken'); | |
action.setParams({ | |
'code' : code | |
}); | |
action.setCallback(this, function(response){ | |
var status = response.getState(); | |
if(status === "SUCCESS"){ | |
var accessToken = response.getReturnValue(); | |
component.set("v.accessToken", accessToken); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
} | |
}, | |
doAuth : function(component, event, helper) { | |
var action = component.get("c.createAuthURL"); | |
action.setCallback(this, function(response){ | |
var status = response.getState(); | |
if(status === "SUCCESS"){ | |
var authUrl = response.getReturnValue(); | |
window.location.href = response.getReturnValue(); | |
} | |
}); | |
$A.enqueueAction(action); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment