GitHub Authentication from a WPF Application using Username & Password

Eoin Campbell

I'm developing a small WPF Application which will sit on top of a Local Git Repo.

It's a Line-Of-Business app to allow some business users to edit some files via a GUI and then push them back up to GitHub

I'm using the LibGit2Sharp libraries to handle all the git commands, but I'd also like to force the users to login to the application using their GitHub credentials everytime the application is loaded.

I've been looking at the OAuth2 libraries & some existing nuget packages (http://johnnycode.com/GitHubOAuth2Client/) but they all seem to revolve around a web based app, and require client id's and secret keys.

Can anyone point me in the direction of a simple API that will take a username & password and return a simple success/fail for the login attempt or am I stuck writing my own wrapper around the GitHub API

Eoin Campbell

I ended up solving this with a simple REST call to the older v2 API passing UserName & Password in the auth headers while requesting a specific repo. Then checking the permissions that came back on the requested Repo.

private class Permissions
{
     public bool Admin { get; set; }
     public bool Push { get; set; }
     public bool Pull { get; set; }
}

private class GitHubRepo
{
     public Permissions Permissions { get; set; }
     public string Name { get; set; }
}

public bool Authenticate(string userName, string password)
{
    try
    {
        var apiUrl = "https://api.github.com/";
        var resource = "repos/myAccount/";
        var repoName = "myRepo";

        var client = new RestClient
            {
                BaseUrl = apiUrl,
                Authenticator = new HttpBasicAuthenticator(userName, password)
            };

        var request = new RestRequest {Resource = string.Join("", resource, repoName)};

        var response = client.Execute<List<GitHubRepo>>(request);
        if ((int) response.StatusCode >= 200 && (int) response.StatusCode < 209)
        {
            if (response.Data.Any(r => r.Name == repoName))
            {
                var repo = response.Data.Single(r => r.Name == repoName);

                if (repo.Permissions.Admin || (repo.Permissions.Pull && repo.Permissions.Push))
                {
                    return true;
                }
            }
        }

        return false;
    }
    catch
    {
        return false;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Posting tweets using username and password authentication from Java app

From Dev

Using JDBC to implement username and password authentication

From Dev

get google authentication token using username and password

From Java

Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API

From Dev

How to fetch username and password from url using basic authentication in node.js?

From Dev

Username and Password for LDAP Authentication

From Dev

How to add authentication(Username/Password) in Twisted client server application in python?

From Dev

How to automatically authenticate into GitHub from Git Bash using my Public and Private Keys instead of username and password?

From Java

GitHub: invalid username or password

From Dev

spring security authentication using ip address and username password

From Dev

Svn Authentication username, password and URL using Svn Kit

From Dev

Git server with username and password authentication

From Dev

Client/server username/password authentication

From Dev

Authentication via username and password in Cassandra

From Dev

Get email password from WPF application

From Dev

How to change username and password in MVC 4 application using Simple membership

From Dev

Authentication using username or email

From Dev

Send username and password to another application

From Dev

Android How Get Responce from Web Server from the following URL With Authentication UserName and Password

From Dev

Git clone with username password authentication in one go

From Dev

Authentication with username & password with node js, AngularJs and JWT

From Dev

Selfhosted WCF Service with SSL and Username and Password authentication

From Dev

remote: Invalid username or password, fatal: Authentication failed for

From Dev

Google Drive API username + password authentication

From Dev

How long can a basic authentication username/password be?

From Dev

Print username and password used in spring security authentication

From Dev

Chatting authentication of password and username to get IP and port

From Dev

Eclipse Luna Not Storing Proxy Authentication Username and Password

From Dev

Thrift sasl with username/password authentication for C++

Related Related

  1. 1

    Posting tweets using username and password authentication from Java app

  2. 2

    Using JDBC to implement username and password authentication

  3. 3

    get google authentication token using username and password

  4. 4

    Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API

  5. 5

    How to fetch username and password from url using basic authentication in node.js?

  6. 6

    Username and Password for LDAP Authentication

  7. 7

    How to add authentication(Username/Password) in Twisted client server application in python?

  8. 8

    How to automatically authenticate into GitHub from Git Bash using my Public and Private Keys instead of username and password?

  9. 9

    GitHub: invalid username or password

  10. 10

    spring security authentication using ip address and username password

  11. 11

    Svn Authentication username, password and URL using Svn Kit

  12. 12

    Git server with username and password authentication

  13. 13

    Client/server username/password authentication

  14. 14

    Authentication via username and password in Cassandra

  15. 15

    Get email password from WPF application

  16. 16

    How to change username and password in MVC 4 application using Simple membership

  17. 17

    Authentication using username or email

  18. 18

    Send username and password to another application

  19. 19

    Android How Get Responce from Web Server from the following URL With Authentication UserName and Password

  20. 20

    Git clone with username password authentication in one go

  21. 21

    Authentication with username & password with node js, AngularJs and JWT

  22. 22

    Selfhosted WCF Service with SSL and Username and Password authentication

  23. 23

    remote: Invalid username or password, fatal: Authentication failed for

  24. 24

    Google Drive API username + password authentication

  25. 25

    How long can a basic authentication username/password be?

  26. 26

    Print username and password used in spring security authentication

  27. 27

    Chatting authentication of password and username to get IP and port

  28. 28

    Eclipse Luna Not Storing Proxy Authentication Username and Password

  29. 29

    Thrift sasl with username/password authentication for C++

HotTag

Archive