1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
4  * This file is part of libgit2, distributed under the GNU GPL v2 with
5  * a Linking Exception. For full terms see the included COPYING file.
6  */
7 
8 #ifndef INCLUDE_transports_auth_h__
9 #define INCLUDE_transports_auth_h__
10 
11 #include "common.h"
12 
13 #include "git2.h"
14 #include "netops.h"
15 
16 typedef enum {
17 	GIT_HTTP_AUTH_BASIC = 1,
18 	GIT_HTTP_AUTH_NEGOTIATE = 2,
19 	GIT_HTTP_AUTH_NTLM = 4,
20 } git_http_auth_t;
21 
22 typedef struct git_http_auth_context git_http_auth_context;
23 
24 struct git_http_auth_context {
25 	/** Type of scheme */
26 	git_http_auth_t type;
27 
28 	/** Supported credentials */
29 	git_credential_t credtypes;
30 
31 	/** Connection affinity or request affinity */
32 	unsigned connection_affinity : 1;
33 
34 	/** Sets the challenge on the authentication context */
35 	int (*set_challenge)(git_http_auth_context *ctx, const char *challenge);
36 
37 	/** Gets the next authentication token from the context */
38 	int (*next_token)(git_buf *out, git_http_auth_context *ctx, git_credential *cred);
39 
40 	/** Examines if all tokens have been presented. */
41 	int (*is_complete)(git_http_auth_context *ctx);
42 
43 	/** Frees the authentication context */
44 	void (*free)(git_http_auth_context *ctx);
45 };
46 
47 typedef struct {
48 	/** Type of scheme */
49 	git_http_auth_t type;
50 
51 	/** Name of the scheme (as used in the Authorization header) */
52 	const char *name;
53 
54 	/** Credential types this scheme supports */
55 	git_credential_t credtypes;
56 
57 	/** Function to initialize an authentication context */
58 	int (*init_context)(
59 		git_http_auth_context **out,
60 		const git_net_url *url);
61 } git_http_auth_scheme;
62 
63 int git_http_auth_dummy(
64 	git_http_auth_context **out,
65 	const git_net_url *url);
66 
67 int git_http_auth_basic(
68 	git_http_auth_context **out,
69 	const git_net_url *url);
70 
71 #endif
72