protected void SetMessages(msglist messages) { StringBuilder header = new StringBuilder(); bool emptyHeader = true, encoded = false; const string SystemMsg = "System"; const string UserMsg = "User"; string typeMsg; foreach (msglistItem msg in messages) { if (msg.gxTpr_Type == 0) { string value = msg.gxTpr_Description; encoded = false; if (GXUtil.ContainsNoAsciiCharacter(value)) { value = GXUtil.UrlEncode(value); encoded = true; } typeMsg = msg.IsGxMessage ? SystemMsg : UserMsg; header.AppendFormat("{0}299 {1} \"{2}{3}:{4}\"", emptyHeader ? string.Empty:",", context.GetServerName(), encoded ? GxRestPrefix.ENCODED_PREFIX : string.Empty, typeMsg, value); if (emptyHeader) { emptyHeader = false; } } } if (!emptyHeader) { AddHeader(WARNING_HEADER, header.ToString()); } }
public override void webExecute() { bool isRefreshToken = false; bool isDevice = false; bool isExternalSDAuth = false; String clientId = cgiGet("client_id"); String clientSecret = cgiGet("client_secret"); String grantType = cgiGet("grant_type"); String nativeToken = cgiGet("native_token"); String nativeVerifier = cgiGet("native_verifier"); String avoid_redirect = cgiGet("avoid_redirect"); String additional_parameters = cgiGet("additional_parameters"); String refreshToken = ""; String userName = string.Empty; String userPassword = string.Empty; String scope = string.Empty; string URL = string.Empty; bool flag = false; try { DataStoreUtil.LoadDataStores(context); if (grantType.Equals("refresh_token", StringComparison.OrdinalIgnoreCase)) { refreshToken = cgiGet("refresh_token"); isRefreshToken = true; } else if (grantType.Equals("device", StringComparison.OrdinalIgnoreCase)) { isDevice = true; } else if (!string.IsNullOrEmpty(nativeToken)) { isExternalSDAuth = true; } else { userName = cgiGet("username"); userPassword = cgiGet("password"); scope = cgiGet("scope"); } OutData gamout; GxResult result; if (isRefreshToken) { result = GxSecurityProvider.Provider.refreshtoken(context, clientId, clientSecret, refreshToken, out gamout, out flag); } else if (isDevice) { result = GxSecurityProvider.Provider.logindevice(context, clientId, clientSecret, out gamout, out flag); } else if (isExternalSDAuth) { result = GxSecurityProvider.Provider.externalauthenticationfromsdusingtoken(context, grantType, nativeToken, nativeVerifier, clientId, clientSecret, ref scope, additional_parameters, out gamout, out flag); } else if (String.IsNullOrEmpty(additional_parameters)) { result = GxSecurityProvider.Provider.oauthauthentication(context, grantType, userName, userPassword, clientId, clientSecret, scope, out gamout, out URL, out flag); } else { result = GxSecurityProvider.Provider.oauthauthentication(context, grantType, userName, userPassword, clientId, clientSecret, scope, additional_parameters, out gamout, out URL, out flag); } localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson; if (!flag) { localHttpContext.Response.StatusCode = 401; if (result != null) { string messagePermission = result.Description; HttpHelper.SetResponseStatusAndJsonError(context.HttpContext, result.Code, messagePermission); if (GXUtil.ContainsNoAsciiCharacter(messagePermission)) { messagePermission = string.Format("{0}{1}", GxRestPrefix.ENCODED_PREFIX, Uri.EscapeDataString(messagePermission)); } localHttpContext.Response.AddHeader(HttpHeader.AUTHENTICATE_HEADER, HttpHelper.OatuhUnauthorizedHeader(context.GetServerName(), result.Code, messagePermission)); } } else { if (!isDevice && !isRefreshToken && (gamout == null || String.IsNullOrEmpty((string)gamout["gxTpr_Access_token"]))) { if (string.IsNullOrEmpty(avoid_redirect)) { localHttpContext.Response.StatusCode = 303; } else { localHttpContext.Response.StatusCode = 200; } localHttpContext.Response.AddHeader("location", URL); Jayrock.Json.JObject jObj = new Jayrock.Json.JObject(); jObj.Put("Location", URL); localHttpContext.Response.Write(jObj.ToString()); } else { localHttpContext.Response.StatusCode = 200; localHttpContext.Response.Write(gamout.JsonString); } } context.CloseConnections(); } catch (Exception e) { localHttpContext.Response.StatusCode = 404; localHttpContext.Response.Write(e.Message); GXLogging.Error(log, string.Format("Error in access_token service clientId:{0} clientSecret:{1} grantType:{2} userName:{3} scope:{4}", clientId, clientSecret, grantType, userName, scope), e); } }