Click here to Skip to main content
15,885,979 members

How to capture credentials / token from windows credentials popup dialog?

S p k 521 asked:

Open original thread
Hi Experts,

I have a requirement to access a connected printer device through their embedded web server.
The device had an option to secure its details using username and password.
Once it is set, we can only communicate through "https" to that device.
Also there is windows credentials popup will come from UWP app once we initiate communication through https and wait for the user to enter the correct username and password as in web server.

My requirement is we need to pass those credentials as authorization header for a POST request to that device.

eg:-
Authorization: Basic YWRtaW46MTIzNDU2Nzg5


How to access those Windows credentials in UWP app. Without this authorization token, i am getting HTTP:401 unauthorized error for the POST request.


Please guide me to resolve this issue.

Regards
Spk

What I have tried:

I tried hard coding the username and password entered in the web server.
var username = usrName;
                   var password = pwd;
                   var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"));
                   _httpClient.AuthorizationHeader = new KeyValuePair<string, string>("Basic", base64String);


then in this case the POST request is successful.

Also tried the same in a separate test application. In that case after entering the credentials in the windows credentials popup the same POST request is again sending automatically with those credentials as Basic auth token.
Tags: C#, Universal Windows Platform, Xamarin

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900