Пример #1
0
        public bool TryAuthenticate(string code, string state, string verify, out GithubAccessToken token)
        {
            token = null;

            if (!String.Equals(state, verify, StringComparison.Ordinal))
            {
                return false;
            }

            var post = String.Concat("client_id=", Configuration.ClientId, "&client_secret=", Configuration.ClientSecret, "&code=", code);

            try
            {
                var tokenRequest = new JsonWebRequest("https://github.com/login/oauth/access_token") { PostData = post };
                var response = tokenRequest.Request<TokenResponse>();

                token = new GithubAccessToken() { ReturnUrl = state.Length > 32 ? state.Substring(32) : null, Scope = response.scope, Type = response.token_type, Value = response.access_token };
            }
            catch (Exception e)
            {
                var t = e;
            }

            return token != null;
        }
Пример #2
0
        public bool TryAuthenticate(string code, string state, string verify, out GithubAccessToken token)
        {
            token = null;

            if (!String.Equals(state, verify, StringComparison.Ordinal))
            {
                return(false);
            }

            var post = String.Concat("client_id=", Configuration.ClientId, "&client_secret=", Configuration.ClientSecret, "&code=", code);

            try
            {
                var tokenRequest = new JsonWebRequest("https://github.com/login/oauth/access_token")
                {
                    PostData = post
                };
                var response = tokenRequest.Request <TokenResponse>();

                token = new GithubAccessToken()
                {
                    ReturnUrl = state.Length > 32 ? state.Substring(32) : null, Scope = response.scope, Type = response.token_type, Value = response.access_token
                };
            }
            catch (Exception e)
            {
                var t = e;
            }

            return(token != null);
        }