Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Getting a valid Bearer Token from sharepoint in NAV 17

(0) ShareShare
ReportReport
Posted on by 20

Hello Experts,

Can you please help me to downgrade this Business Central AL Code to NAV17 ?

procedure GetToken() Token: text
    Var
        TypeHelper: Codeunit "Type Helper";
        client: HttpClient;
        cont: HttpContent;
        header: HttpHeaders;
        response: HttpResponseMessage;
        Jobject: JsonObject;
        tmpString: Text;
        granttype: text;
        clientid: text;
        ClientSecret: text;
        resources: text;
        RequestURI_L: Text;
        Jtoken: JsonToken;
        ResponseText: Text;
        tenant: Text;
    Begin
        SharepointSetup_L.Get(UserId);
        granttype := SharepointSetup_L."Grant Type";
        clientid := SharepointSetup_L.Client_Id   '@'   SharepointSetup_L.Tenant;
        ClientSecret := SharepointSetup_L."Client Secret";
        resources := SharepointSetup_L.Resources   '/'   SharepointSetup_L.Domain   '.sharepoint.com@'   SharepointSetup_L.Tenant;
        cont.WriteFrom('grant_type='   TypeHelper.UrlEncode(granttype)   '&client_id='
          TypeHelper.UrlEncode(clientid)   '&client_secret='   TypeHelper.UrlEncode(ClientSecret)
          '&resource='   TypeHelper.UrlEncode(resources)   '');
        cont.GetHeaders(header);
        header.Add('charset', 'UTF-8');
        header.Remove('Content-Type');
        header.Add('Content-Type', 'application/x-www-form-urlencoded');
        RequestURI_L := 'https://accounts.accesscontrol.windows.net/'   SharepointSetup_L.Tenant   '/tokens/oAuth/2';
        client.Post(RequestURI_L, cont, response);
        response.Content.ReadAs(ResponseText);
        Jobject.ReadFrom(ResponseText);
        Jobject.Get('access_token', Jtoken);
        Token := Jtoken.AsValue().AsText();
    end;

  • zizousa2 Profile Picture
    zizousa2 20 on at
    RE: Getting a valid Bearer Token from sharepoint in NAV 17

    Thank you but can you help me to convert this code into C/AL NAV17 please, it will be used to generate a valid Bearer Access Token from Sharepoint to use it to list Sharepoint Library Files list in Navision Item Card in a spesific Listpart

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 75,673 Super User 2024 Season 2 on at
    RE: Getting a valid Oauth2 Token in NAV 17

    Hi, hope the following can give you some hints.

    How can I get an access token from from Azure AD using NAV2017 — mibuso.com

    Thanks.
    ZHU

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans