How to consume api using c# or jquery

Mohammad Qasim 576 Reputation points
2022-01-27T13:14:04.077+00:00

Greetings..

I am using sharepoint 2019 ( FBA)

Solution required..
I have to consumel rest api using application.aspx on c# ( login page )

Api url : 172.16.10.82/api/v1/auth/

Parameter it takes.

Username : test
Token: 122671
Password : abc1234

It should also take basic autorization value
User = admin
Password = 1gayaywhayabay890ba11

These are api paramater and basic authorizarion..( above mentioned )

Please help ,how can i consume this api using c# and jquery..

Note: i have checked api on post man
Working fine..
On authorization basic mode :
username admin
Password : 1gayaywhayabay890ba11

And on body

Username = test,Token=122671,
Password =abc1234

In this way,it works

But how can i consume it on login pge ( FBA)
On sharepoint 2019 on prem.

Please help me out.

Appreciate swift response

Thanks.

Microsoft 365 and Office | SharePoint Server | Development
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-01-28T05:58:22.303+00:00

    Hi @Mohammad Qasim ,
    You can refer to the following code to login sharepoint 2019

    private void SignInUser()  
    {  
        var mem = (MyMembershipProvider) Utils.BaseMembershipProvider();  
        var role = (MyRoleProvider) Utils.BaseRoleProvider();  
        if (!mem.ValidateUser(_userName, _password))  
        {  
            return;  
        }  
      
        SecurityToken token = SPSecurityContext.SecurityTokenForFormsAuthentication  
                                         (new Uri(SPContext.Current.Web.Url),  
                                         mem.Name,  
                                         role.Name,  
                                         _userName,  
                                         _password,  
                                         _remember);  
        SPFederationAuthenticationModule.Current.SetPrincipalAndWriteSessionToken(token);  
      
        Response.Redirect(Request.QueryString["Source"]);  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. sadomovalex 3,636 Reputation points
    2022-02-08T15:21:14.597+00:00

    did I understand correctly that you need to call some custom API endpoint http://172.16.10.82/api/v1/auth from codebehind (C# code which runs on server side) of login page which is used in Sharepoint FBA site? If yes you need to add event handler (e.g. button click) which will cause postback to the server. In handler of this event you need to write code which will send HTTP request to API using basic authentication - like you test it in Postman. Here you may find example how to do that (search for "C# HttpClient Basic authentication"): https://zetcode.com/csharp/httpclient.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.