Exemplo de uso da Classe FWoAuth2Client com Client para LinkedIn.


#Include 'Protheus.ch'
#Include 'Parmtype.ch'


User Function LinkedIn()
Local oAuth, cResult


    oAuth := FWLinkedIn():New("", "") // App Key e App Secret

    oAuth:GetMethods(.T.)

    I18nConOut("#1#1#2#1", {CRLF, "Waiting for response..."})

    cResult := oAuth:Access("https://api.linkedin.com/v1/people/~")
    I18nConOut("#1Result: #2 #1", {CRLF, cResult})

    I18nConOut("#1Token used: #2 #1", {CRLF, oAuth:GetToken()})

    oAuth:Destroy()

Return 


Class FWLinkedIn From FWoAuth2Client

    Data aScopes

    Method New() CONSTRUCTOR
    Method Destroy()
    Method ClassName()
    Method SetScopes()
    Method Access()

EndClass

Method New(cConsumer,cSecret) Class FWLinkedIn
Local oURL      := FwoAuth2Url():New("https://www.linkedin.com/uas/oauth2/authorization", "https://www.linkedin.com/uas/oauth2/accessToken")

    _Super:New(cConsumer,cSecret,oURL)

    ::SetScopes({"r_basicprofile"})

    ::SetAsCode()
    ::SetQueryAuthorization("oauth2_access_token")
    
    ::SetGetAuthorizationRequest()
    ::SetGetTokenRequest()
    
Return Self

Method Destroy() Class FWLinkedIn
Return _Super:Destroy()

Method ClassName() Class FWLinkedIn
Return "FWLinkedIn"

Method SetScopes(aScopes) Class FWLinkedIn
Local cScope
Local nI

PARAMTYPE 0 VAR aScopes AS ARRAY OPTIONAL Default {}

    ::aScopes := aScopes

    For nI := 1 to Len(aScopes)
        If nI == 1
            cScope := "scope="+aScopes[nI]
        Else
            cScope += "%20" + aScopes[nI]
        EndIf
    Next 

    ::SetAuthOptions(cScope)

Return Len(aScopes) > 0

Method Access(cURLResource, cQuery, cBody, lGet, aHeader) Class FWLinkedIn
Local cResult := ""

Default lGet := .T.

    cResult := _Super:Access(cURLResource, cQuery, cBody, lGet, @aHeader)

Return cResult