コード例 #1
0
        public static OauthToken GetRequestToken(string baseUrl, AvansOauthHelperOptions options)
        {
            // Creating a new instance with a helper method
            OAuthRequest client = OAuthRequest.ForRequestToken(options.AvansClientId, options.AvansSecret);

            client.RequestUrl  = "https://publicapi.avans.nl/oauth/request_token";
            client.CallbackUrl = baseUrl + "/api/account/AvansCallback";

            // Using URL query authorization to get the request token
            string auth     = client.GetAuthorizationQuery();
            var    url      = client.RequestUrl + "?" + auth;
            var    request  = (HttpWebRequest)WebRequest.Create(url);
            var    response = (HttpWebResponse)request.GetResponse();

            Stream       receiveStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(receiveStream, Encoding.UTF8);
            string       body          = reader.ReadToEnd();

            //TY for the concistent response avans
            var uri = body.Replace("php&", "php?");

            uri = uri.Split("authentification_url=")[1];

            return(AvansOauthHelper.getTokenFormUri(uri));
        }
コード例 #2
0
        public static OauthToken GetAccesToken(AvansOauthHelperOptions options, OauthToken requestToken, string verifier)
        {
            // Creating a new instance with a helper method
            OAuthRequest client = OAuthRequest.ForAccessToken(options.AvansClientId, options.AvansSecret, requestToken.Token, requestToken.Secret);

            client.Verifier   = verifier;
            client.RequestUrl = "https://publicapi.avans.nl/oauth/access_token";

            // Using URL query authorization to get the request token
            string auth     = client.GetAuthorizationQuery();
            var    url      = client.RequestUrl + "?" + auth;
            var    request  = (HttpWebRequest)WebRequest.Create(url);
            var    response = (HttpWebResponse)request.GetResponse();

            Stream       receiveStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(receiveStream, Encoding.UTF8);
            string       body          = reader.ReadToEnd();

            //turn body into uri
            var uri = "http://temp?" + body;

            return(AvansOauthHelper.getTokenFormUri(uri));
        }