Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Suggested answer

Getting a valid Bearer Token from sharepoint in NAV 17

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 68,539 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,137 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans