Forum

Web authentication
 
Notifications
Clear all

Web authentication

9 Posts
3 Users
0 Reactions
108 Views
(@mgaindahotmail-com)
Posts: 8
Active Member
Topic starter
 

Is there a simple way of access web content that requires authentication?

 
Posted : 14/05/2019 7:02 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Mohinder,

When you enter the web URL the next dialog box will ask you how you want to connect to the page and whether you need to enter any credentials.

Mynda

 
Posted : 14/05/2019 7:38 am
(@mgaindahotmail-com)
Posts: 8
Active Member
Topic starter
 

Hi Mynda

Not sure What I am missing. When I click on OK I do not get an option to connect.

Please see the attached.

Thank you

Mohinder

 
Posted : 14/05/2019 12:36 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Mohinder,

You only get this dialog box the very first time you connect to the web page and after that it remembers your choice. You needed to select 'Basic' and then you can enter your credentials. See images attached.

mohinder_pq_web1.pngmohinder_pq_web2.png

However, you can edit the settings via the Power Query editor File tab > Options & Settings > Data Source Settings > Edit Permissions > Edit Credentials.

Mynda

 
Posted : 14/05/2019 7:31 pm
(@mgaindahotmail-com)
Posts: 8
Active Member
Topic starter
 

Hi Mynda

Thank you I am able to get the Credentials dialog box. However even through the credentials are correct,  I am unable to log in. Have I missed some thing?

 

Mohinder

InvaildCredentials.PNG

 
Posted : 15/05/2019 4:55 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Mohinder,

Looks like there are some problems with authentication at the moment. More is explained here along with some workarounds.

Mynda

 
Posted : 15/05/2019 7:51 pm
(@mgaindahotmail-com)
Posts: 8
Active Member
Topic starter
 

Just for information See attached. Worked for me.

Mo

 
Posted : 26/05/2019 7:43 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi,

Depends on the way authentication is designed on each site.

Some sites require simple authentication with username and pass provided in binary format in the request content, but they provide a temporary access token.

Source = Json.Document(Web.Contents(URLString, [Headers=[#"Content-Type"="application/x-www-form-urlencoded",
                                                                           Accept="application/json"],
                                                                           Content=Text.ToBinary("username=" & User & "&password=" & Pass)])),
token = Source[token]

With this token, data can be extracted, but the token needs to be passed to a custom header:

Source = Xml.Tables(Web.Contents(URLString, [Headers=[#"X-Auth-Token"=Token]])),

If the website requires, Power Query can encode user and pass:

Token = Text.From(Excel.CurrentWorkbook(){[Name="Parameters"]}[Content]{0}[API Token]),
WID=Text.From(Excel.CurrentWorkbook(){[Name="Parameters"]}[Content]{0}[Workspace ID]),
Credentials=Binary.ToText(Text.ToBinary(Token & ":api_token"), BinaryEncoding.Base64),
Source = Json.Document(Web.Contents("https://toggl.com/reports/api/v2/details?workspace_id="& WID &"&since="& FromDate &"&until="& ToDate &"&user_agent=api_test",[Headers=[#"Authorization"="Basic " & Credentials]])),

Some sites require a bearer token:

JsonData = Json.Document(Web.Contents("https://api.onedrive.com/v1.0/drive/root:/" & Uri.EscapeDataString(FolderPath) & ":/children", [Headers=[#"Accept" = "application/json", #"Authorization" = "bearer " & Token]]),1252),

 

In conclusion, each site documentation must be studied, they usually provide all authentication details to access their data.

 
Posted : 26/05/2019 12:25 pm
(@mgaindahotmail-com)
Posts: 8
Active Member
Topic starter
 

Thank you Catalin.

Great -detailed answer.

Mo

 
Posted : 27/05/2019 4:43 am
Share: