How to Authenticate for the first time

DiscogsAuth auth = New DiscogsAuth("UserAgent", "YourConsumerKey", "YourConsumerSecret");
Process.Start(Auth.AuthenticateUser())
String AuthHeaders; //To store the auth headers for this session

This will open a new window of the predefined browser (Opera, Chrome, etc...) and after login and authorization it will give an code to input on your app
AuthHeaders = Auth.AuthorizeApp(pin); //the is the code that's given on the browser

This concludes the authorization code if you don't want the credentials to be stored you just need to close the app and reopen you will see that the session has been destroied

Access the user content after logging in

UserAPI UserInfo = new UserAPI("UserAgent", AuthHeaders)

How to save the Credentials

This step need to be done during the authorization process!
So insert the following code after
AuthHeaders = Auth.AuthorizeApp(pin);

Dictionary<string, string> tokens = Auth.GrabTokens();
My.Settings.Token = tokens("token");
My.Settings.TokenSecret = tokens("token_secret");
My.Settings.Save();

Make sure you have an setting called Token and TokenSecret you can also save this to an ini file or any other method... Remember this will authorize the user to login and they aren't your Token and Consumer keys.

Login with saved credentials

DiscogsAuth Auth = new DiscogsAuth("UserAgent", "ConsumerKey", "ConsumerSecret")
string AuthHeaders = Auth.RegenerateHeaders(My.Settings.Token, My.Settings.TokenSecret)
UserAPI UserInfo = New UserAPI("UserAgent", AuthHeaders)

Last edited Jun 17, 2014 at 7:25 PM by Hitmanpt, version 1

Comments

toxiKgoaT Apr 5, 2016 at 2:20 AM 
Does not work or the examples are just lacking. I have the token and tokenSecret, no problem, but what do you do with them after that? All I can get is "include them with your call" Ultimatly I am trying to do a Search, there is nothing in the code that adds AuthHeaders, is this right? Is this project just dead and out of date?

DavixDevelop Nov 29, 2015 at 2:44 PM 
Why must this be so complicated?

Blair_ob Feb 9, 2015 at 8:00 AM 
I can't get this working, i an struggling to comprehend the order to do things. I have registered the app in Discogs and got the key and private key. Then done the "How to Authenticate for the first time". Then all turns to custard.