Beispiel #1
0
        private string GetAccessTokenV2(OdsTokenSettings settings)
        {
            var authCodeResponse  = GetAuthCodeResponse(settings);
            var authTokenResponse = GetAuthTokenResponse(settings, authCodeResponse);

            return(authTokenResponse.Access_token);
        }
Beispiel #2
0
        public string GetAccessToken(OdsTokenSettings settings)
        {
            if (settings.Version == EdFiVersion.v2)
            {
                return(GetAccessTokenV2(settings));
            }

            if (settings.Version == EdFiVersion.v3)
            {
                return(GetAccessTokenV3(settings));
            }

            throw new NotImplementedException($"Access token retreiver not supported for Ed-Fi version {settings.Version}");
        }
Beispiel #3
0
        private TokenResponse GetAuthTokenResponse(OdsTokenSettings settings)
        {
            var client = new RestClient(settings.TokenUrl);

            var request = new RestRequest(Method.POST);

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("Client_id", settings.ClientId);
            request.AddParameter("Client_secret", settings.ClientSecret);
            request.AddParameter("Grant_type", "client_credentials");

            var response = client.Execute(request);

            return(JsonConvert.DeserializeObject <TokenResponse>(response.Content));
        }
Beispiel #4
0
        private AuthCodeResponse GetAuthCodeResponse(OdsTokenSettings settings)
        {
            var client = new RestClient(settings.AuthUrl)
            {
                Timeout = -1
            };

            var request = new RestRequest(Method.POST);

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("Client_id", settings.ClientId);
            request.AddParameter("Response_type", "code");

            IRestResponse response = client.Execute(request);

            return(JsonConvert.DeserializeObject <AuthCodeResponse>(response.Content));
        }