public async Task <bool> CASLogin(string serviceName, string serviceSecret, string userId) { //Step 1 - Request on behalf transient token BatchServiceTransientToken transientToken = await GetTransientToken(serviceName, serviceSecret, userId); // Step 2 - build the login request string loginUrl = GetEndpointURL(LOGIN_TRANSIENT_TICKET_WS); RestRequest loginRequest = new RestRequest(loginUrl, Method.GET, DataFormat.Json); loginRequest.AddQueryParameter(TGT, transientToken.access_token); IRestResponse loginRequestResponse = await Client.ExecuteGetAsync(loginRequest); if (loginRequestResponse.StatusCode != System.Net.HttpStatusCode.OK) { //handle according to established exception policy //throw new PassportException(""); } m_authenticationIdentity = SimpleJson.DeserializeObject <BatchServicePassportAuthentication>(loginRequestResponse.Content); if ((m_authenticationIdentity != null) && (m_authenticationIdentity.message.Equals(AUTHENTICATED, StringComparison.InvariantCultureIgnoreCase))) { return(IsCookieAuthenticated); } return(false); }
private async Task <BatchServiceTransientToken> GetTransientToken(string serviceName, string serviceSecret, string userId) { //Step 1 - Request transient token RestRequest getTransientTokenRequest = new RestRequest(GetEndpointURL(GET_TRANSIENT_TICKET_WS)); getTransientTokenRequest.AddQueryParameter(IDENTIFIER, userId); getTransientTokenRequest.AddHeader(DS_SERVICE_NAME, serviceName); getTransientTokenRequest.AddHeader(DS_SERVICE_SECRET, serviceSecret); IRestResponse getTransientTokenResponse = await Client.ExecuteGetAsync(getTransientTokenRequest); if (getTransientTokenResponse.StatusCode != System.Net.HttpStatusCode.OK) { //handle according to established exception policy //TODO: throw } //Handle ticket login response BatchServiceTransientToken transientToken = SimpleJson.DeserializeObject <BatchServiceTransientToken>(getTransientTokenResponse.Content); if (transientToken.token_type != TRANSIENT_TOKEN) { //handle according to established exception policy //TODO: throw } ; return(transientToken); }